OK, I am creating a business listing site that is using a custom taxonomy for the listing "type". I need to display two loops on the taxonomy archive page, one for "sponsored" listings and one for regular ones.

taxonomy archive: http://pastie.org/3187162

pagination function: http://pastie.org/3187168

Both parts are doing exactly what I want, with one hitch: there are approx 50 non-sponsored listings in a specific category, but the 2nd query is maxing out at 5 "pages" (i.e. 25 listings if I set posts_per_page to 5, 35 if I set posts_per_page to 7)

I'm stumped. Any ideas?


FWIW, I've been testing the code layout here: http://www.kriesi.at/archives/how-to-build-a-wordpress-post-pagination-without-plugin and it's working a bit better, in that I get the total number of "pages" it should have. But it still gives me a 404 after page 5.

  • Do you have more non-sponsored than sponsored listings? If you change those around so that there are more of whatever there are less of now, does the category that cannot list all its posts change?
    – mor7ifer
    Jan 15, 2012 at 4:48
  • @m0r7if3r I'm not sure what you mean, but they're being displayed in the order I have to have them in. Both numbers can be variable, i.e. one type can have more sponsored than non-sponsored and vice versa.
    – Norcross
    Jan 15, 2012 at 5:01
  • Basically, what I'm thinking is that it is doing the pagination for the category with less entries, and when it reaches the end of those posts, it doesn't detect the second query, so the rest of the posts from the category with more entries cannot be displayed
    – mor7ifer
    Jan 15, 2012 at 15:17
  • possible duplicate of How Do I Configure Automatic Updates in WordPress 3.7? Oct 29, 2013 at 22:34

2 Answers 2


The issue is that before your custom queries load, WordPress runs the main taxonomy query (all results in that tax term, 10 per page). On page 6, the main query is trying to load posts 51-60, and since they don't exist the page 404's before you have a chance to load your custom query.

Customize the main query using the pre_get_posts hook so that the second loop you're doing is the main query. Add this to functions.php: https://gist.github.com/1616098

Then for your second loop, just do:

if( have_posts() ): while( have_posts() ): the_post();

More information: http://www.billerickson.net/customize-the-wordpress-query/

  • perfect! that was it. I had a feeling it was tied to the main posts per page setting.
    – Norcross
    Jan 15, 2012 at 15:16

Output the wp_query object on the 404 and see what is going on inside. It may provide some insight.

On your 404 template add global $wp_query; print_r($wp_query);

  • Thanks for the heads up. In doing so, I could see that it was grabbing the posts per page setting from the back-end. I change it to match the query in question, and it work.
    – Norcross
    Jan 15, 2012 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.