admin管理员组

文章数量:1418380

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'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;
Share Improve this question asked Jul 30, 2019 at 12:28 OrtsOrts 11 bronze badge 3
  • 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 Commented Jul 30, 2019 at 13:54
  • do you have any 'sticky' posts? try to explicitely exclude them from the query. – Michael Commented Jul 31, 2019 at 4:46
  • @Michael WOW man you are the king! thanks for the answer, this was the issue it seems. thanks a lot! – Orts Commented Jul 31, 2019 at 12:13
Add a comment  | 

1 Answer 1

Reset to default -1

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

'ignore_sticky_posts' => 1

本文标签: Wordpress posts loop paginationfirst page return 125 posts instead of 10 and the rest return 10