#20767 closed defect (bug) (fixed)
tax_query clobbers tag and category
Reported by: | wonderboymusic | Owned by: | wonderboymusic |
---|---|---|---|
Milestone: | 3.8 | Priority: | normal |
Severity: | major | Version: | 3.1 |
Component: | Query | Keywords: | has-patch commit |
Focuses: | 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 (4)
Change History (20)
#1
follow-up:
↓ 3
@
13 years ago
I'm not sure using $this->get( 'cat' )
is much better: you can have ?cat=1,2,-3
.
#3
in reply to:
↑ 1
@
12 years 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
#4
@
12 years ago
can I get a 3.5 amen from the congregation? tax_query has been breaking theme functions for a while now
#5
@
12 years 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
#6
@
12 years 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
#8
@
11 years ago
- Milestone changed from Future Release to 3.7
Patch still applies, this was a really annoying issue I had to work around in multiple places
#9
@
11 years ago
- Keywords commit added
Added unit tests to cover tag / category pages with a tax_query
injection - tag / category should be the queried object. Related: #5358.
#10
@
11 years ago
- Milestone changed from 3.7 to 3.8
Unfortunately it's too late for this, but let's do it in early 3.8.
#11
@
11 years ago
Added a new patch, gonna let this stew for a lil bit - I think WP_UnitTestCase::go_to()
is doing something weird. Some of my assertions that I was trying were returning is_home() === true
for a custom taxonomy, which means some other unit tests might be returning false positives. Will inwestigate.
#13
@
11 years ago
- Owner set to wonderboymusic
- Resolution set to fixed
- Status changed from new to closed
In 26007:
#15
@
11 years ago
Specifically, on a default install with pretty permalinks, when you visit /category/uncategorized, then the 'cat' variable is not set.
Instead, the category_name is 'uncategorized', and there is a tax_query with
'category' as the taxonomy and 'uncategorized' as the term. You cannot only use get('cat') here. This probably breaks tags in a similar way for the same reasons.
Patch for WP_Query->get_queried_object