Opened 13 months ago
Closed 8 months ago
#20604 closed defect (bug) (fixed)
Empty tax_query returns all posts
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 3.5 |
| Component: | Query | Version: | 3.3.1 |
| Severity: | minor | Keywords: | has-patch |
| Cc: | me@…, kovshenin@… |
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)
- Summary changed from get_posts tax_query to Empty tax_query returns all posts
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.
I see the current behaviour as not a bug. I see the proposed behaviour as as unexpected bug.
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!
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.
wonderboymusic — 9 months ago
comment:9
wonderboymusic — 9 months 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.
comment:10
scribu — 9 months ago
- Milestone changed from Awaiting Review to 3.5
comment:11
ryan — 8 months ago
comment:12
ryan — 8 months ago
- Owner set to ryan
- Resolution set to fixed
- Status changed from new to closed
In [22109]:

That's consistent with 'meta_query', 'post__in', etc. We should fix it everywhere, if possible.