The WordPress admin reading settings only allow you to define the number of posts per page once for blog posts, this is then applied globally to all post types which is sometimes not desirable. This isn’t really an issue if you are writing a bespoke query directly in a template, but for the most part it’s much more convenient and less work to simply use the templates the correct way and allow WordPress to generate the query for you.

The following snippet allows you to define the number of posts per page for one or more custom post types and their respective taxonomies, by utilising the ‘pre_get_posts’ filter. If you want the number of posts to be unlimited with no pagination, set ‘posts_per_page’ to -1

Just change the post type and taxonomy namespaces accordingly and pop the code above in your theme’s functions.php file. Remember that it’s important to restrict the use of this function to the theme only and not the admin area, so be sure to catch this when adding the filter.



Notify of