最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Wordpress posts loop pagination - first page return 125 posts instead of 10 and the rest return 10

programmeradmin1浏览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'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
发布评论

评论列表(0)

  1. 暂无评论