Wordpress query_posts posts_per_page not working

2019-08-03 11:19发布

问题:

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();

回答1:

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();


回答2:

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?!



回答3:

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.



标签: wordpress