这个tax_query 属性是您所需要的。
你可以这样使用它:
$query_args = array(
\'tax_query\' => array(
\'relation\' => \'AND\',
array(
\'taxonomy\' => \'category\',
\'field\' => \'slug\',
\'terms\' => array( \'slug-of-category-a\' ),
),
array(
\'relation\' => \'OR\',
array(
\'taxonomy\' => \'category\',
\'field\' => \'slug\',
\'terms\' => array( \'slug-of-category-b\' ),
),
array(
\'taxonomy\' => \'category\',
\'field\' => \'slug\',
\'terms\' => array( \'slug-of-category-c\' ),
),
),
),
);
$query = new WP_Query( $query_args );
或者,利用“IN”操作符(默认情况下在查询术语时用于tax\\u查询)已经作为“Or”条件的事实,您还可以编写:
$query_args = array(
\'tax_query\' => array(
\'relation\' => \'AND\',
array(
\'taxonomy\' => \'category\',
\'field\' => \'slug\',
\'terms\' => array( \'slug-of-category-a\' ),
),
array(
\'taxonomy\' => \'category\',
\'field\' => \'slug\',
\'terms\' => array( \'slug-of-category-b\', \'slug-of-category-c\' ),
),
),
);
$query = new WP_Query( $query_args );
这将获得同时位于和中的帖子:
B、C、B和C。有关更多选项,请参阅我链接的文档。