Full stack web developer, interested in all the things, but especially the web, code, design, Linux, OS X, PHP, WordPress, JavaScript & robots.

Tagged: loops

WordPress Pagination Fix for Loop with Custom Post Types

I’ve recently combined my WordPress custom post types into a single loop on my homepage. The code to do this was fairly trivial and well documented.

However, using the above function by itself caused a problem with pagination. Basically, the pagination routine did not seem to be aware that I was combining my custom post types and only counted regular posts. This meant that if I paged past the number of regular posts, I would hit a 404 error. To fix this, I’ve included the following function in my theme’s functions.php file.

The function tests for paging and whether or not the custom post type is set. If paging is set and the custom post type is not set, it will push a value into the query string to force the loop to count all post types. I’m not sure if anyone else will find this useful, but I thought I should post it.