好的,然后试试这个,它会提取你的术语并排除你不想要的术语,我没有检查它是否有效,但这是逻辑,请检查sintax错误。
$terms = get_terms("sectors");
$count = count($terms);
$termsAr = array();
if ($count > 0 ){
foreach ( $terms as $term ) {
if($term->name !== "healthcare"){//Here we exclude the term or terms we dont want to show
array_push($termsAr, $term->name);
}
}
}
$terms = get_terms("types");
$count = count($terms);
$termsAr2 = array();
if ($count > 0 ){
foreach ( $terms as $term ) {
if($term->name !== "healthcare"){//Here we exclude the term or terms we dont want to show
array_push($termsAr2, $term->name);
}
}
}
$args = array(
'post_type' => 'case-studies',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'sectors',
'field' => 'slug',
'terms' => $termsAr //excluding the term you dont want.
),
array(
'taxonomy' => 'types',
'field' => 'slug',
'terms' => $termsAr2 //excluding the term you dont want.
)
)
);
$query = new WP_Query( $args );