WP_Query 多分类 [英] WP_Query Multiple Categories
本文介绍了WP_Query 多分类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的类别结构如下:
Music
-Genre
-Pop
-Rock
-Role
-Vocalist
-Guitarist
所以现在我想以帖子应该属于(流行或摇滚)和(歌手)的方式过滤帖子
So Now I want to filter posts in such a way that a post should belong to ( either Pop or Rock) and (Vocalist)
所以在流派和与角色之间的或之间
So an or between genres and an and with the role
所以在 wordpress 术语中需要多个 category_in 或 category_and 其中有 category_in
So speaking in wordpress terms in need multiple category_in or category_and which has category_in
很棘手吧?
有什么解决办法吗?
推荐答案
试试这个,看看它是否有效.
Try this and see if it works.
$args = array(
'post_type' => 'post',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => array( 'vocalist' ),
),
array(
'relation' => 'OR',
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => array( 'pop' ),
),
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => array( 'rock' ),
),
),
),
);
$query = new WP_Query( $args );
这篇关于WP_Query 多分类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文