Solution: Wordpress Pagination Stays On Same Page
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.
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);