admin管理员组文章数量:1386760
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
)
),
本文标签: meta queryHow to use orderby with metaquery
版权声明:本文标题:meta query - How to use orderby with meta_query? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744574240a2613526.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论