Wordpress query_posts posts_per_page not working

2019-08-03 10:34发布

Can't figure out why this is not limiting the posts_per_page. It is displaying a very long list of posts, but I only want to show 4

query_posts('posts_per_page=4&post_type=page&pagename=media');

if(have_posts() ) :
while(have_posts()) : the_post();

标签: wordpress
3条回答
We Are One
2楼-- · 2019-08-03 11:22

Please try wp_reset_query(); before your code.

// Reset Query
wp_reset_query();
query_posts('posts_per_page=4&post_type=page&pagename=media');

if(have_posts() ) :
while(have_posts()) : the_post();
查看更多
再贱就再见
3楼-- · 2019-08-03 11:27

I had this same problem on a wordpress site and I tried all the ways to find that site was using Posts per category plugin which was overriding the posts_per_page argument.

查看更多
老娘就宠你
4楼-- · 2019-08-03 11:29

You are resetting the query each time. You need to include the existing query string, otherwise when you paginate the pagination information will be lost.

Try this instead.

global $query_string;
query_posts( $query_string . '&post_type=page&pagename=media' );

Also to note, if you are specifing a specific page with pagename=media then how can than paginate, it should only return one page?!

查看更多
登录 后发表回答