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
1 Answer
Reset to default -1The 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
版权声明:本文标题:Wordpress posts loop pagination - first page return 125 posts instead of 10 and the rest return 10 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745281205a2651432.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论