Current query:
if ( get_query_var('paged') ) { $paged = get_query_var('paged'); } else if ( get_query_var('page') ) {$paged = get_query_var('page'); } else {$paged = 1; }
$args_main = array(
'cat' => $my_categories_variable,
'posts_per_page' => 3,
'paged' => $paged
);
$main_posts_query = new WP_Query($args_main);
while($main_posts_query->have_posts()) : $main_posts_query->the_post();
Problem: Echoing echo $main_posts_query->max_num_pages;
gives me 4, yet I am only able to navigate (via get_next_posts_link()
) to www.mywebsite/page/3/.
Am I missing something? Please do let me know if you need more information.
Thank you!
Current query:
if ( get_query_var('paged') ) { $paged = get_query_var('paged'); } else if ( get_query_var('page') ) {$paged = get_query_var('page'); } else {$paged = 1; }
$args_main = array(
'cat' => $my_categories_variable,
'posts_per_page' => 3,
'paged' => $paged
);
$main_posts_query = new WP_Query($args_main);
while($main_posts_query->have_posts()) : $main_posts_query->the_post();
Problem: Echoing echo $main_posts_query->max_num_pages;
gives me 4, yet I am only able to navigate (via get_next_posts_link()
) to www.mywebsite/page/3/.
Am I missing something? Please do let me know if you need more information.
Thank you!
You're assigning three different values to your variable:
if ( get_query_var('paged') )
{
$paged = get_query_var('paged');
}
else if ( get_query_var('page') )
{
$paged = get_query_var('page');
}
else
{
$paged = 1;
}
Short explanation:
single.php
, singular.php
and other single view templates: (int) $page
Is the page of the post, as specified by the query var page: get_query_var( 'page' );
archive.php
and similar archive/post type list view templates: (int) $paged
Is the global variable contains the page number of a listing of posts (as in archives).Core uses a lot of (slightly confusing) globals (so don't blame yourself).
I have used the following code (which is basically the same as yours) but it did not work for me when using WP_Query($args).
if ( get_query_var( 'page' ) > 1) { $paged = get_query_var( 'page' ); } elseif ( get_query_var( 'paged' ) > 1) { $paged = get_query_var( 'paged' ); } else { $paged = 1; }
Although it's not recommended, pagination began working for me when I changed WP_Query($args) to query_posts($args) and then adjusted The Loop accordingly.
if ( get_query_var('paged') ) { $paged = get_query_var('paged'); } else if ( get_query_var('page') ) {$paged = get_query_var('page'); } else {$paged = 1; } $args_main = array( 'cat' => $my_categories_variable, 'posts_per_page' => 3, 'paged' => $paged ); query_posts($args_main); while(have_posts()) : the_post();
NOTE: As Kaiser noted in his comment below query_posts() can screw things up. At the very least reset the query after The Loop.
wp_reset_query();