Here is the code I'm using.
$paged = get_query_var( 'page' ) ? get_query_var( 'page' ) : 1;
$args = array(
'post_status' => 'publish',
'post_type' => 'portfolio',
'posts_per_page' => 4,
'paged' => $paged,
);
$portfolios = new WP_Query( $args );
while ( $portfolios->have_posts() ) : $portfolios->the_post();
// Title, content and stuff...
endwhile;
next_posts_link( esc_html__( 'Load more', 'text-domain'), $portfolios->max_num_pages );
wp_reset_postdata();
Let's assume we have 15 portfolios. The function generates links like below.
Page 1: SITE_ADDRESS/page/2
Page 2: SITE_ADDRESS/page/2
Page 3: SITE_ADDRESS/page/2
Page 4: Nothing
However, $paged
and $portfolios->max_num_pages
return right values all the time. Any idea why this is not working as expected?