0

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?

1 Answer 1

0

use this:

get_query_var('paged') instead of get_query_var('page')

  $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;

hope this will help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.