This was a big head banger.
If you are are using query_posts multiple times on a page, and are trying to paginate the second loop on the page, the following
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
will always return 1, Unless you place wp_reset_query() below the previous loop.
rewind_posts();
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts(
array(
'cat'=>'5',
'orderby'=>'date',
'order'=>'DESC'
)
);
if(have_posts())
{
?>
// Post template goes here.
}
wp_reset_query();
?>
Pagination should now work for the next loop.

6 Comments »
I was having the same problem about a month back. Your solution is better than mine…
$wp_query = new WP_Query();
$paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
$wp_query->query(‘orderby=post_date&order=DESC&paged=’ . $paged);
Then to draw the pagination I had..
max_num_pages); ?>
The reason I had to pass a 2nd param was cause for some reason the next_posts_link function was not tallying max_num_pages properly (even after the function globals the $wp_query var)… Passing it in directly seemed to work.
Thanks for the tip!
Gah it stripped my 2nd code block :/
next_posts_link(__(‘« Older Entries’), $wp_query->max_num_pages);
I’m still banging my head, but thanks for this post, and thank you Jordan for your code, which worked for me perfectly. I was not getting anything from next_posts_link until I added that little snippet.
Re-reading, I decided to try and see if I could use the code above, as it seemed more elegant. But I’m using a new wp_query, rather than query_posts, to pull in a series of posts within a static page template. Don’t really know how that makes things different, but I quickly realized that I’d gotten it fixed, and should not mess around.
Hi,
I’m just trying my luck here and would appreciate any help on the below.
I need some help on the following. Basically, I have 2 different categories called ‘Deals & Offers’ and ‘San Francisco’ where by each categories has several posts under them.
Now, I’m trying to create a category/page called ‘Deals & Offers in San Francisco’, whereby the page will query and show posts (assuming there are 20 posts under both these categories) that are categorized in ‘Deals & Offers’ and ‘San Francisco’. This category/page will have its own navigation of Next and Previous links when it exceeds more than 5 posts.
I applied the code below, but everytime I clicked on the Previous/Next button, it keep showing the most recent 5 posts (categorized under Deals & Offers and San Francisco)…
How can I possibly show the other remaining 15 posts when I click thru the Next link? Any advice or help would be very much appreciated.. as I have been googling hign and low for this solution, and it seems like nobody has tackle this before?
Hope to get some positive answers. Thanks!
$paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
$wp_query->query(
array(‘category__and’=>array(64,112), ‘posts_per_pages’=>5, ‘&paged’ => $paged));
This was cross posted from (http://wordpress.org/support/topic/382340)
Thankyou Jordon, Ive just spent 2 hours trying to get all these other solutions to work…in the end Ive combined yours with another:
wp_reset_query();
$paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $wp_query->query(‘cat=20&paged=’.$paged);
if ( have_posts() ) : while ( have_posts() ) : the_post();
end loop
wp_reset_query();
I’m having the same problem on my blog and have been banging my head for 6 months.
Where would I apply the changes on the new version of genesis?
Thanks
J
Leave a comment