There is a page displaying the 3 most popular posts, using the post views on the query. When there are no post views, I don't want to display any posts.
How can I display no post when post_views_count
is 0? I think I'm missing something in my meta query. What's wrong?
$query_args = array(
'post_type' => 'list',
'posts_per_page' => 3,
'meta_key' => 'post_views_count',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'meta_query' => array(
array(
'meta_key' => 'post_views_count',
'value' => 50,
'compare' => '>'
)
),
);
There is a page displaying the 3 most popular posts, using the post views on the query. When there are no post views, I don't want to display any posts.
How can I display no post when post_views_count
is 0? I think I'm missing something in my meta query. What's wrong?
$query_args = array(
'post_type' => 'list',
'posts_per_page' => 3,
'meta_key' => 'post_views_count',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'meta_query' => array(
array(
'meta_key' => 'post_views_count',
'value' => 50,
'compare' => '>'
)
),
);
Share
Improve this question
edited Jan 28, 2022 at 20:26
Dave Romsey
17.9k11 gold badges56 silver badges70 bronze badges
asked Jan 28, 2022 at 5:39
Fernando SouzaFernando Souza
1512 silver badges11 bronze badges
1 Answer
Reset to default 3Here's an updated example that appears to do what you want. See the docs for meta queries for details.
$query_args = [
'post_type' => 'list',
'posts_per_page' => 3,
'orderby' => 'meta_value_num',
'order' => 'DESC',
'meta_query' => [
[
'key' => 'post_views_count',
'value' => 50,
'compare' => '>',
'type' => 'NUMERIC',
],
],
];
$post_views_query = new WP_Query( $query_args );