I'm trying to query a customer post type where the results may be within one of several associated terms. The issue however is that only the first term yellow-gold-jewellery
is being returned for, and all others excluded.
See my query below, by default the WP Query docs note that the operator
on the 0
entry of my tax_query
should be IN
. Despite this it is only returning products in the yellow-gold-jewellery
and neither of the latter two.
{
"posts_per_page": 9,
"status": "publish",
"tax_query": {
"0": {
"taxonomy": "jewellery_metal",
"field": "slug",
"terms": [
"yellow-gold-jewellery",
"white-gold-jewellery",
"rose-gold-jewellery"
]
},
"1": {
"taxonomy": "jewellery_availability",
"field": "slug",
"terms": [
"sold",
"unaccounted"
],
"operator": "NOT IN"
},
"relation": "AND"
},
"per_page": "9",
"post_type": "product"
}
I've tried restructuring this several ways:
- Nesting with an OR relation separate to the top level AND
- Removing the top level AND
- Manually adding operator IN to object
0
None have worked and the above seems to be exactly what is prescribed by WP docs.
I have done the obvious in checking that none of the items trip the secondary AND condition (they don't) and removing the yellow-gold-jewellery
then defers to the white-gold-jewellery
(and still not the rose-gold-jewellery
).
It's as if it's only finding the first matched term and nothing else.
Is this how this is supposed to work? Or have I misunderstood the syntax/structure?
yellow-gold-jewelry
is just appearing first? Keep in mind thatNOT IN
is extremely expensive and involves copying the table so it can run the query on a temporary table in memory ( minus the bits you didn't want ). It would be much faster to list every single term in thejewellery_availability
except those two than it would be to useNOT IN
operator
parameter, andper_page
andposts_per_page
are both defined