I making wp_query that control comment-count, and meta key value. So, I coded like this. but is doesn't work. When I use comment_cout only or meta_query only, it works good. when I use together, it doesn't work normally. Can I get some help? Thank you.
<?php
$arg = array(
'post_type' => 'race',
'posts_per_page' => 5,
'comment_count' => array(
array(
'value' => 10,
'compare' => '>=',
),
),
'meta_query' => array(
// 'relation' => 'AND',
array(
'key' => 'race_date',
'value' => $today, //this is get by php time() function. ex) 2018-12-10
'compare' => '>=',
),
),
'orderby' => array(
'comment_count' => 'DESC',
),
);
$query = new WP_Query( $arg );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
$postid = get_the_ID();
the_title();
echo '<br />';
}
wp_reset_postdata();
}
?>
I making wp_query that control comment-count, and meta key value. So, I coded like this. but is doesn't work. When I use comment_cout only or meta_query only, it works good. when I use together, it doesn't work normally. Can I get some help? Thank you.
<?php
$arg = array(
'post_type' => 'race',
'posts_per_page' => 5,
'comment_count' => array(
array(
'value' => 10,
'compare' => '>=',
),
),
'meta_query' => array(
// 'relation' => 'AND',
array(
'key' => 'race_date',
'value' => $today, //this is get by php time() function. ex) 2018-12-10
'compare' => '>=',
),
),
'orderby' => array(
'comment_count' => 'DESC',
),
);
$query = new WP_Query( $arg );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
$postid = get_the_ID();
the_title();
echo '<br />';
}
wp_reset_postdata();
}
?>
The inline documentation of WP_Query
has this:
Filter results by comment count. Provide an integer to match comment count exactly. Provide an array with integer 'value' and 'compare' operator ('=', '!=', '>', '>=', '<', '<=' ) to compare against comment_count in a specific way.
So there should only be one array, not 2 like with a meta query:
'comment_count' => array(
'value' => 10,
'compare' => '>=',
),
var_dump($query->request);
and take a look at the generated SQL. I don't think it will change anything but I always add"TYPE"=>"DATE"
as an argument when I do a date based meta query. – jdp Commented Dec 5, 2018 at 1:13