或者,您可以将这两个查询分成五个查询(根据您获取条件的方式,编写代码可能更容易)。
了解这两种结构之间的性能是否有任何差异是很有意思的(@Frank Martin或其他任何人,如果您可以共享每种方式生成的实际SQL,那就太好了-我将此答案设置为社区wiki。)
[tax_query] => Array
(
[relation] => AND
[0] => Array
(
[taxonomy] => services
[field] => term_id
[terms] => Array
(
[0] => 3
)
[operator] => IN
)
[1] => Array
(
[taxonomy] => services
[field] => term_id
[terms] => Array
(
[0] => 10
)
[operator] => IN
)
[2] => Array
(
[taxonomy] => services
[field] => term_id
[terms] => Array
(
[0] => 6
)
[operator] => IN
)
[3] => Array
(
[taxonomy] => services
[field] => term_id
[terms] => Array
(
[0] => 9
)
[operator] => IN
)
[4] => Array
(
[taxonomy] => awards
[field] => term_id
[terms] => Array
(
[0] => 13
)
[operator] => IN
)
[5] => Array
(
[taxonomy] => awards
[field] => term_id
[terms] => Array
(
[0] => 12
)
[operator] => IN
)
)
。
正如我在处理最近的高级分类查询问题时发现的那样,How to pass URL parameters for advanced taxonomy queries with multiple terms for one custom taxonomy 如果您通过URL传递查询,WP就会这样做(至少在3.1.4中是这样)。