I am having an issue on an archive page. Everything seems to be working fine, exept the fact that "the_query" returns only two posts, when it should return 10 of them.
I wanted to debug the query so I used the following line :
echo "<hr>Last SQL-Query: {$the_query->request}";
Which returns :
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) WHERE 1=1 AND ( wp_postmeta.meta_key = 'client' ) AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') GROUP BY wp_posts.ID ORDER BY wp_postmeta.meta_value DESC LIMIT 0, 2
When I run it in phpMyAdmin, it returns 2 IDs. When I remove the end (" LIMIT 0, 2"), it then returns the 10 IDs I was expecting.
Where does this limit come from ? I am quite suprised !
Here is my php code :
$the_query = new WP_Query
(
array
(
'meta_key'=> 'client',
'orderby' => 'meta_value',
'order' => 'DESC'
)
);
echo "<hr>Last SQL-Query: {$the_query->request}";
I then have another bit that displays posts, but it works fine since the two posts are displayed properly.
Thank you for your help !
I am having an issue on an archive page. Everything seems to be working fine, exept the fact that "the_query" returns only two posts, when it should return 10 of them.
I wanted to debug the query so I used the following line :
echo "<hr>Last SQL-Query: {$the_query->request}";
Which returns :
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) WHERE 1=1 AND ( wp_postmeta.meta_key = 'client' ) AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') GROUP BY wp_posts.ID ORDER BY wp_postmeta.meta_value DESC LIMIT 0, 2
When I run it in phpMyAdmin, it returns 2 IDs. When I remove the end (" LIMIT 0, 2"), it then returns the 10 IDs I was expecting.
Where does this limit come from ? I am quite suprised !
Here is my php code :
$the_query = new WP_Query
(
array
(
'meta_key'=> 'client',
'orderby' => 'meta_value',
'order' => 'DESC'
)
);
echo "<hr>Last SQL-Query: {$the_query->request}";
I then have another bit that displays posts, but it works fine since the two posts are displayed properly.
Thank you for your help !
Share Improve this question asked Oct 25, 2016 at 6:37 Grégoire LlorcaGrégoire Llorca 571 silver badge10 bronze badges1 Answer
Reset to default 2Use the posts_per_page
parameter in your WP_Query
to show a given number of posts.
When you don't provide this parameter, the query takes default value which can be set in backend on https://example/wp-admin/options-reading.php.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745207727a4616672.html
评论列表(0条)