admin管理员组文章数量:1122846
I have this code which shouldn't return all the post in DB. It should return only 3 posts.
$sql = "SELECT wp_posts.ID
FROM wp_posts
WHERE 1=1 AND ((wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish'
OR wp_posts.post_status = 'private')))
ORDER BY wp_posts.post_date DESC
LIMIT 0, 3";
global $wpdb;
$results = $wpdb->get_results( $sql, ARRAY_A );
$rids = wp_list_pluck($results,'ID');
$car_args = array('post__in'=>$rids,'posts_per_page'=>3,'orderby'=>'date','order'=>'DESC');
$custom_car_query = new WP_query($car_args);
echo '<!--<div>_'.$custom_car_query->post_count.'--'.$custom_car_query->request.'</div>-->';
It says that were found and returned 28 posts, but it does haves limit LIMIT 0, 3
<!--<div>_28
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID
FROM wp_posts
WHERE 1=1 AND wp_posts.ID IN (1964,1961,1958) AND ((wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish'
OR wp_posts.post_status = 'private')))
ORDER BY wp_posts.post_date DESC
LIMIT 0, 3
</div>-->
It is from a loop. Tried to set the IDS which I wanted, also tried with
$car_args = array('posts_per_page'=>$car_total,'orderby'=>'date','order'=>'DESC');
$custom_car_query = new WP_query($args);
Works on test enviroment, but not on production. Did a backup copy of the production, running on test... Just changed the Data Base, whithout touching the code. The problem vanished, returned to the same DB on production, the bug returned.
My guess is something in the DB... Hard to know...
本文标签: wp querywpquery returns all posts even with postin and postsperpage
版权声明:本文标题:wp query - wp_query returns all posts even with post__in and posts_per_page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736299210a1930400.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论