admin管理员组文章数量:1304186
I want show (featured product) that instock, but this query just show in stock products.
$query = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => 12,
'orderby' => 'date',
'order' => 'DESC',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '_stock_status',
'value' => 'instock',
),
array(
'taxonomy' => 'product_visibility',
'field' => 'name',
'terms' => 'featured',
),
),
);
I want show (featured product) that instock, but this query just show in stock products.
$query = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => 12,
'orderby' => 'date',
'order' => 'DESC',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '_stock_status',
'value' => 'instock',
),
array(
'taxonomy' => 'product_visibility',
'field' => 'name',
'terms' => 'featured',
),
),
);
Share
Improve this question
edited Feb 3, 2021 at 9:40
och
asked Feb 3, 2021 at 9:12
ochoch
391 silver badge8 bronze badges
2
|
1 Answer
Reset to default 1You mixed meta query and tax query
It should look like this
$query = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => 12,
'orderby' => 'date',
'order' => 'DESC',
'meta_query' => array(
array(
'key' => '_stock_status',
'value' => 'instock'
)
),
'tax_query' => array(
array(
'taxonomy' => 'product_visibility',
'field' => 'name',
'terms' => 'featured'
)
)
);
本文标签: Meta Query relation “AND” not working
版权声明:本文标题:Meta Query relation “AND” not working 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741779501a2397224.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
tax_query
.. You should put it in ameta_query
, i.e.'meta_query' => array( array( ... ) )
. – Sally CJ Commented Feb 3, 2021 at 9:26