admin管理员组文章数量:1425869
I have the following WP_Query:
$query = new WP_Query(array(
'post_type' => 'some_cpt',
'posts_per_page' => -1,
'meta_key' => 'active',
'meta_value' => 1,
'orderby' => 'ranking',
'order' => 'ASC'
));
Both active
and raking
are ACF fields, True/False
and Numeric
respectively. I am trying to get all some_cpt
posts that have active
set to true and at the same time order them by ranking
. However, the code above totally ignores orderby
.
I have the following WP_Query:
$query = new WP_Query(array(
'post_type' => 'some_cpt',
'posts_per_page' => -1,
'meta_key' => 'active',
'meta_value' => 1,
'orderby' => 'ranking',
'order' => 'ASC'
));
Both active
and raking
are ACF fields, True/False
and Numeric
respectively. I am trying to get all some_cpt
posts that have active
set to true and at the same time order them by ranking
. However, the code above totally ignores orderby
.
1 Answer
Reset to default 0You have to use "orderby" => "meta_value_num"
and set a "meta_query"
at the same time. Then choose the "meta_key"
you want to order by.
Try:
$query = new WP_Query(
array(
'post_type' => 'some_cpt',
'posts_per_page' => - 1,
'meta_query' => array(
array(
'key' => 'active',
'value' => '1',
'compare' => '=',
)
),
'meta_key' => 'ranking',
'orderby' => 'meta_value_num',
'order' => 'ASC',
)
);
本文标签: advanced custom fieldsWP Query with meta queries
版权声明:本文标题:advanced custom fields - WP Query with meta queries 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745459540a2659259.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论