Opened 12 years ago
Closed 12 years ago
#20604 closed defect (bug) (fixed)
Empty tax_query returns all posts
Reported by: | Ninos Ego | Owned by: | ryan |
---|---|---|---|
Milestone: | 3.5 | Priority: | normal |
Severity: | minor | Version: | 3.3.1 |
Component: | Query | Keywords: | has-patch |
Focuses: | Cc: |
Description
have got this codesnippet in the args
'tax_query' => array( 'relation' => 'OR', array( 'taxonomy' => 'taxonomy1', 'field' => 'id', 'terms' => 'sometimes false or clear', 'operator' => 'IN' ), array( 'taxonomy' => 'taxonomy2', 'field' => 'id', 'terms' => 'sometimes false or clear', 'operator' => 'IN' ) ),
if in tax 1 and tax 2 there's no term, I get all posts. I think I should get than no posts...
Think, thats a bug, hope you can fix it in the next version
Attachments (1)
Change History (13)
#3
@
12 years ago
I'm not sure I'd call this a bug when you're specifically specifying tax_query. I also believe it's been covered in a previous ticket.
Simply ignoring the specific query parts if there isn't content doesn't seem right to me, The above request for example is "I specifically want posts IN tax1 in the list (none) OR IN tax2 in the list (none)", to receive a response of "Here's a list of posts that match the rest of your args, but may not be related to tax1 or tax2 at all" would seem like buggy behaviour to me.
#5
@
12 years ago
I see the current behaviour as not a bug. I see the proposed behaviour as an unexpected buggy behaviour (to a developer)
#6
follow-up:
↓ 7
@
12 years ago
Ok, so you think that "Here's a list of posts that match the rest of your args, but may not be related to tax1 or tax2 at all" is a bug.
But that's not the proposed behavior; it's the current behavior!
#7
in reply to:
↑ 6
@
12 years ago
Replying to scribu:
But that's not the proposed behavior; it's the current behavior!
You're right.. I've misread it.. Sounds like a bug to me if that's the way it's currently acting.
#9
@
12 years ago
- Keywords has-patch added; needs-patch removed
Yep - the problem is the OR relation, the script bails the loop early and doesn't tell the where clause that the tax_query is garbage. To test:
$q = new WP_Query( array( 'fields' => 'ids', 'tax_query' => array( 'relation' => 'OR', array( 'taxonomy' => 'post_tag', 'field' => 'id', 'terms' => false, 'operator' => 'IN' ), array( 'taxonomy' => 'category', 'field' => 'id', 'terms' => false, 'operator' => 'IN' ) ) ) ); print_r( $q->posts ); exit();
Should return an empty array - does so with my patch, attached.
That's consistent with
'meta_query'
,'post__in'
, etc. We should fix it everywhere, if possible.