你可以有两个以上。您可以有任意多个,但如果您尝试使用太多,可能会导致性能下降。我希望这是真的,尤其是如果你使用OR
关系
有关创建tax_query
动态阵列。
https://wordpress.stackexchange.com/a/97444/21376
为了适应您的环境,只需将每个术语与其分类法相关联。
$def = array(
\'field\' => \'slug\',
\'operator\' => \'NOT IN\'
);
$cities = array(
\'boston\' => \'tax_city\',
\'chicago\' => \'tax_city\',
\'texas\' => \'tax_state\',
\'california\' => \'tax_state\'
);
$args = array(\'relation\' => \'OR\');
foreach ($cities as $term => $tax) {
$args[] = wp_parse_args(
array(
\'taxonomy\'=>$tax,
\'terms\'=>$term
),
$def
);
}
print_r($args);
可以对嵌套循环执行相同的操作。
$cities = array(
\'tax_city\' => array(
\'boston\',
\'chicago\'
),
\'tax_state\' => array(
\'texas\',
\'california\'
)
);
foreach ($cities as $tax => $terms) {
foreach ($terms as $term) {
$args[] = wp_parse_args(
array(
\'taxonomy\'=>$tax,
\'terms\'=>$term
),
$def
);
}
}
print_r($args);