Pagination on 2nd loop

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

Read More

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?

UPDATE

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.

Related posts

Leave a Reply

2 comments

  1. 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/

  2. 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);