我想编写一个查询来查找分类法。一个条件是taxonomyA返回x,第二个条件是taxonomyB返回空。我不知道如何查询空的。
这就是我所拥有的:
$args = [
\'post_type\' => \'post\',
\'tax_query\' => [
\'relation\' => \'AND\',
[
\'taxonomy\' => \'areaoflondon\',
\'field\' => \'name\',
\'terms\' => \'South London\',
\'include_children\' => false,
],
[
\'taxonomy\' => \'yearofvisit\',
\'field\' => \'name\',
\'terms\' => \'\',
\'include_children\' => false,
]
],
\'posts_per_page\' => 5,
\'meta_key\' => \'rating\',
\'meta_type\' => \'NUMERIC\',
\'order\' => \'DESC\',
\'orderby\' => \'meta_value_num\',
];
但是,这不会返回任何结果。
如何查询分类法是否为空?有可能吗?
谢谢詹姆斯
最合适的回答,由SO网友:iwillbeawebdeveloper 整理而成
感谢Sally提供的答案,即使用NOT EXISTS运算符:
$args = [
\'post_type\' => \'post\',
\'tax_query\' => [
\'relation\' => \'AND\',
[
\'taxonomy\' => \'areaoflondon\',
\'field\' => \'name\',
\'terms\' => \'South London\',
\'include_children\' => false,
],
[
\'taxonomy\' => \'yearofvisit\',
\'operator\' => \'NOT EXISTS\'
]
],
\'posts_per_page\' => 5,
\'meta_key\' => \'rating\',
\'meta_type\' => \'NUMERIC\',
\'order\' => \'DESC\',
\'orderby\' => \'meta_value_num\',
];