0

I'm trying to show 10 posts per page with pagination on WordPress and the first page return 125 posts instead of 10 and the rest of the pages return 10 posts as requested, please assist :)

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$output = array();
global $post;
$args = array('nopaging' => false, 'paged' => $paged, 'posts_per_page' => 10, 'post_type' => 'post', 'order'=> 'DES', 'orderby' => 'date');
$postslist = new WP_Query( $args );

    if ( $postslist->have_posts() ) :
        while ( $postslist->have_posts() ) : $postslist->the_post(); 

    array_push($output, array("timestamp" => get_the_date('U'),"img_url" => get_the_post_thumbnail_url(), "title" => get_the_title(), "text" => get_the_content()));
         endwhile;  

        wp_reset_postdata();
    endif;
  • I think the problem is pagination part. For example, there are 136 items, the pagination section on first page shows 1 and 2, but 2nd page shows 1,2,3,...13. So I think you need to implement your own pagination code. – idpokute Jul 30 '19 at 13:54
  • do you have any 'sticky' posts? try to explicitely exclude them from the query. – Michael Jul 31 '19 at 4:46
  • @Michael WOW man you are the king! thanks for the answer, this was the issue it seems. thanks a lot! – Orts Jul 31 '19 at 12:13
-1

The sticky posts was the problem, Thanks to @Michael answer, I have excluded the sticky_posts from the query

'ignore_sticky_posts' => 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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