I want to write a query that looks up taxonomies. One condition is that taxonomyA returns x, and a second condition is that taxonomyB returns empty. I don't know how to query for empty.
This is what I have:
$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',
];
However this doesn't return any results.
How can I query that a taxonomy is empty? Is it even possible?
Thanks James
I want to write a query that looks up taxonomies. One condition is that taxonomyA returns x, and a second condition is that taxonomyB returns empty. I don't know how to query for empty.
This is what I have:
$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',
];
However this doesn't return any results.
How can I query that a taxonomy is empty? Is it even possible?
Thanks James
Share Improve this question asked Feb 20, 2022 at 9:57 iwillbeawebdeveloperiwillbeawebdeveloper 1212 silver badges8 bronze badges 5
[ 'taxonomy' => 'yearofvisit', 'operator' => 'EXISTS' ]
– Sally CJ Commented Feb 20, 2022 at 12:01NOT EXISTS
operator, depending on what the "empty taxonomy" means in your code/context. – Sally CJ Commented Feb 20, 2022 at 12:11