admin管理员组文章数量:1405516
I have this code which works fine:
$args = array(
'post_type' => 'brands',
'meta_query' => array(
array(
'key' => 'br_type',
'value' => 'Aviation'
)),
'posts_per_page' => -1,
'meta_key' => 'br_name',
'orderby' => 'meta_value',
'order' => 'ASC',
'fields' => 'ids'
);
However, I need to order first by ascending order by another custom field "br_category"
and then by the name br_name
. I am not sure how to implement this.
I have this code which works fine:
$args = array(
'post_type' => 'brands',
'meta_query' => array(
array(
'key' => 'br_type',
'value' => 'Aviation'
)),
'posts_per_page' => -1,
'meta_key' => 'br_name',
'orderby' => 'meta_value',
'order' => 'ASC',
'fields' => 'ids'
);
However, I need to order first by ascending order by another custom field "br_category"
and then by the name br_name
. I am not sure how to implement this.
- I found my answer here! wordpress.stackexchange/a/126928/15209 – Jacob Raccuia Commented Jul 11, 2020 at 4:35
1 Answer
Reset to default 3 +25I'm not 100% certain what specific order you're asking for, but you just need to assign an associative array to the 'orderby' value. Here's an example:
$args = array(
'post_type' => 'brands',
'meta_query' => array(
array(
'key' => 'br_type',
'value' => 'Aviation'
),
array(
'key' => 'br_category'
),
array(
'key' => 'br_name'
)
),
'posts_per_page' => -1,
'orderby' => [
'br_category' => 'ASC',
'br_name' => 'ASC',
'br_type' => 'ASC'
],
'order' => 'ASC',
'fields' => 'ids'
);
本文标签: wp queryOrder by two meta keys
版权声明:本文标题:wp query - Order by two meta keys 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744920829a2632282.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论