#29416 closed defect (bug) (invalid)
WP_Query tax_query :: terms array with one item doesn't query properly
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.9.2 |
Component: | Query | Keywords: | reporter-feedback |
Focuses: | Cc: |
Description
Consider this simple query:
$products = new WP_Query( array( 'post_type' => 'product', 'posts_per_page' => -1, 'orderby' => 'date', 'order' => 'DESC', 'meta_query' => array( array( 'key' => 'active', 'compare' => '=', 'value' => 'Yes' ) ), 'tax_query' => array( array( 'taxonomy' => 'product_type', 'field' => 'slug', 'terms' => array('accessories'), 'operator' => 'NOT IN' ) ) ) );
When tax_query[terms] is an array with a single element, this tax_query has no effect. When I take 'accessories' out of the array, it works as expected. It would make sense to allow an array as the operator 'NOT IN' basically means 'item NOT IN array', not necessarily 'item NOT IN item'.
Per the documentation: http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters
- terms can accept: int/string/array
However, it does not list any limitations when accounting for number of items to test against.
Change History (3)
#2
@
9 years ago
- Resolution set to invalid
- Status changed from new to closed
Interestingly enough, I tried this again doing both methods, and they both yielded the same request (query). I am certain it was not functioning properly in my initial report along with different tests!
Either way, thank you for following up. I'll be closing the ticket. If it happens again, I'll be sure to test back and forth several times and try to reproduce on a stock WP instance.
Thanks
Thanks for the report Rob.
I'm unable to reproduce the problem. This is the SQL generated (excluding the meta query for brevity):
Some things to check:
accessories
term actually exist in theproduct_type
taxonomy on your site?$products->request
to see what the SQL looks like.terms
array?