Opened 13 months ago
Last modified 5 weeks ago
#20767 new defect (bug)
tax_query clobbers tag and category
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | Query | Version: | 3.1 |
| Severity: | major | Keywords: | has-patch |
| Cc: |
Description
The main query should return a tag or category as its queried object if tax_query is applied to a tag or category archive page. It currently returns the first term derived from the WP_Query->tax_query->queries array which does not include the tag or category as a term in the request. WP_Query->tax_query->queries is a portion of the request, but not the request. Because WP_Query sets is_tag and is_category flags, they have to be captured before dealing with is_tax
The result of this bug is that theme functions return the wrong data because the wrong term is returned with get_queried_object.
Real world example: at eMusic, we pass regions into pre_get_posts to regionalize the content that is returned. On a tag page, if you are in the US, we pass the regions "ALL" and "US" to make sure you are looking at appropriate content. Here's what the title for the archives looks like - (spoiler: It's "ALL" when it should be "Daily Download"):
http://www.emusic.com/17dots/topics/daily-download/
I am attaching a patch.
Attachments (2)
Change History (9)
wonderboymusic
— 13 months ago
comment:1
follow-up:
↓ 3
scribu
— 13 months ago
I'm not sure using $this->get( 'cat' ) is much better: you can have ?cat=1,2,-3.
comment:3
in reply to:
↑ 1
wonderboymusic
— 12 months ago
Replying to scribu:
I'm not sure using $this->get( 'cat' ) is much better: you can have ?cat=1,2,-3.
It works, if you have a URL like so: www.emusic.com/17dots/topics/daily-download/?cat=1,2,3,4
- is_tag is true
- is_category is true
- cat returns 1 (the first category id)
- tag_id returns 8376, which is correct
The public query is correct:
array(2) {
'cat' =>
string(7) "1,2,3,4"
'tag' =>
string(14) "daily-download"
}
is_tag takes precedence over is_category and should
comment:4
wonderboymusic
— 11 months ago
can I get a 3.5 amen from the congregation? tax_query has been breaking theme functions for a while now
comment:5
markoheijnen
— 11 months ago
I really don't see the issue. If you handle category or post_tag as a custom taxonomy you wouldn't have the issue right?
I rather go for something like that then adding code for only category or post_tag
wonderboymusic
— 5 months ago
comment:6
wonderboymusic
— 5 months ago
- Milestone changed from Awaiting Review to 3.6
The fact that we are already doing this:
if ( $this->is_category || $this->is_tag || $this->is_tax ) {
....
}
...means we need to check them before arbitrarily grabbing the first term in the stack
Patch for WP_Query->get_queried_object