[wp-hackers] Taxonomy - Custom Post Type - Pagination?
Joaquin Rodriguez Montero
yojoaquin at gmail.com
Mon Sep 20 19:39:22 UTC 2010
You rock Philip. Thanks a lot for your answer!
Still.. it's odd how this works on taxonomies but not on other *regular*
pages.. for instance this works perfectly on page-products.php
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts("post_type=products&paged=$page&posts_per_page=16&orderby=title&order=ASC");
$i = 1; while (have_posts()) : the_post();
Any idea why this is?
J
-------------------------------------------
Message: 2
Date: Mon, 20 Sep 2010 06:14:04 -0700
From: "Philip M. Hofer \(Frumph\)" <philip at frumph.net>
Subject: Re: [wp-hackers] Taxonomy - Custom Post Type - Pagination?
To: <wp-hackers at lists.automattic.com>
Message-ID: <47E634F81B964B44B96E754A56364941 at frumph.net>
Content-Type: text/plain; format=flowed; charset="iso-8859-1";
reply-type=original
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
More information about the wp-hackers
mailing list