admin管理员组

文章数量:1122833

I'm merging 2 queries using the code below and it works as I expected except for the $main_query->found_posts; returning 0.

$args = array(
                'post_type' => 'carellcars',
                'posts_per_page' => $per_page,
                'paged' => $cur_page,
                'meta_key' => !empty( $_GET['sortby'] ) ? strpos( $_GET['sortby'], "post_" ) !== false ? "" : $_GET['sortby'] : "", 
                'orderby' => 'rand',
                'order' => 'rand',                      
                'meta_query' => sizeof( $meta_query ) == 1 ? "" : $meta_query 
        );


$args_featured = array(
    'post_type' => 'carellcars',
    'meta_query' => array(
            array(
                'key' => 'featured',
                'value' => 'Yes',
                'compare' => '='
            )
            
    )
    
    );
    
    

//setup your queries as you already do
$featured_query = new WP_Query($args_featured);
$sub_main_query = new WP_Query($args);

//create new empty query and populate it with the other two

$main_query = new WP_Query();
$main_query->posts = array_merge( $featured_query->posts, $sub_main_query->posts );

//populate post_count count for the loop to work correctly
$main_query->post_count = $featured_query->post_count + $sub_main_query->post_count;

echo "<br><br>";
echo $main_query->found_posts;

本文标签: wp querywpquerygtfoundposts returns zero