tax_query operator – changing
-
Is there a way to change the operator for a given taxonomy? I took a look and it looks like you’re checking for a value for it (class-gallery.php, line 600):
'operator' => isset($operator[$taxon]) ? $operator[$taxon] : 'IN'
But since it doesn’t look like we can pass an operator value to the shortcode, it always defaults to
IN
. This results in anOR
statement within the taxonomy.For instance, the tax query I’m getting out when I’m going for limiting it to two
attachment_category
values and a singleattachment_tag
value is:[tax_query] => Array ( [relation] => AND [0] => Array ( [taxonomy] => attachment_category [field] => id [terms] => Array ( [0] => 114 [1] => 162 ) [operator] => IN ) [1] => Array ( [taxonomy] => attachment_tag [field] => id [terms] => Array ( [0] => 161 ) [operator] => IN ) )
I end up with anything in either category 114 or 162 that also has tag 161, rather than entries that are in 114 and 162 that also have tag 161. I can solve this by setting the
operator
toAND
, which I’ve done manually at the line mentioned above.So, just checking to see if I’m overlooking an option I can pass to the shortcode. If not, are you looking to add this as an argument to the shortcode in the future?
I realize the
tax_query
options can get pretty tricky: do you only allow one value, eliminating the option to have mixed relationship queries, or do you accept a comma delimited value that you can use to set the operator for each taxonomy? And that’s without getting into the complexities of supporting nestedtax_query
s that were introduced in 4.1.
- The topic ‘tax_query operator – changing’ is closed to new replies.