I want to order posts by views after filtering them with meta_query by a specific meta_key.
Using this query I was able to order posts by views but I was unable to order only the posts with the 'meta_key' => 'my_choices'.
$args = array(
'post_type'=> 'post',
'posts_per_page'=> 24,
'meta_key' => 'wpb_post_views_count',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'meta_query' =>
array(
array(
'meta_key' => 'my_choices',
'meta_value' => '1',
)
),
);
$wp_query = new WP_Query($args);
$i=0; while ($wp_query->have_posts()) : $wp_query->the_post(); ++$i;
Anyone know how can this be done?
Thanks
I want to order posts by views after filtering them with meta_query by a specific meta_key.
Using this query I was able to order posts by views but I was unable to order only the posts with the 'meta_key' => 'my_choices'.
$args = array(
'post_type'=> 'post',
'posts_per_page'=> 24,
'meta_key' => 'wpb_post_views_count',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'meta_query' =>
array(
array(
'meta_key' => 'my_choices',
'meta_value' => '1',
)
),
);
$wp_query = new WP_Query($args);
$i=0; while ($wp_query->have_posts()) : $wp_query->the_post(); ++$i;
Anyone know how can this be done?
Thanks
Share Improve this question asked Apr 12, 2020 at 20:00 MaxMax 31 bronze badge1 Answer
Reset to default 2You have used wrong parameters for meta_query.
It should be -
'meta_query' => array(
array(
'key' => 'my_choices', // not meta_key
'value' => '1', // not meta_value
)
),