admin管理员组文章数量:1414874
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.
本文标签: wp queryWPQuerygtrequest has a limit
版权声明:本文标题:wp query - WP_Query->request has a limit 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745207727a2647718.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论