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
版权声明:本文标题:wp query - $wp_query->found_posts; returns zero 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736309465a1934033.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论