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