[wp-hackers] Taxonomy - Custom Post Type - Pagination?

Jeremy Clarke jer at simianuprising.com
Mon Sep 20 15:28:45 UTC 2010

On Mon, Sep 20, 2010 at 9:14 AM, Philip M. Hofer (Frumph) <philip at frumph.net
> wrote:

> Well the reason is the posts_per_page when set in the query line doesn't
> actually work unless you send it to the pre_get_posts first, the reason is
> that the calculation for pagination happens *way* before the query is done,
> dunno why, just does.
>  add_filter('pre_get_posts', 'comicpress_blogpostcount_filter');
>  function comicpress_blogpostcount_filter($query) {
>  if (is_home()) {
>   $query->set('posts_per_page', 16);
>  }
>  return $query;
>  }
> So basically you need to set it at the pre_get_posts stage ahead of time so
> that it can calculate the posts_per_page properly
This is very interesting and explains something I never had time to track
down that has made paging miscount the total pages pretty much any time you
start doing interesting things with posts_per_page.

Is it that it uses the global posts_per_page from Settings > Reading? Isn't
that a bug? Seems like WP should recalculate the max number of pages for
custom queries if they have a non-default posts_per_page value.

Jeremy Clarke | http://jeremyclarke.org
Code and Design | http://globalvoicesonline.org

More information about the wp-hackers mailing list