Opened 3 years ago
Closed 3 years ago
#11904 closed enhancement (fixed)
Conditional tag for terms
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 3.0 |
| Component: | Taxonomy | Version: | 2.9.1 |
| Severity: | normal | Keywords: | has-patch tested commit |
| Cc: | pavelevap@… |
Description
Conditional tag for terms would be very helpfull. There is is_tax() for taxonomies but from WordPress 2.9 it does not work for terms in taxonomies. So any function is_tax_term() would be fine (see http://core.trac.wordpress.org/ticket/10721).
Attachments (3)
Change History (20)
- Component changed from General to Taxonomy
- Keywords has-patch added
- Owner changed from filosofo to ryan
Replying to scribu:
I don't think $term should be optional.
Why not? It's parallel to is_category, for which the specific category is optional.
function is_category($category = '') {
return is_tax_term('category', $category);
}
How about we add $term as an optional parameter to is_tax(), directly?
It seems more intuitive.
I was actually going to suggest we add an optional parameter $taxonomy to is_term()... but, well:
function is_term($term, $taxonomy = '', $parent = 0)
Why isn't that sufficient?
Replying to scribu:
How about we add $term as an optional parameter to is_tax(), directly?
It seems more intuitive.
I'm good with that. Second patch does that.
function is_term($term, $taxonomy = '', $parent = 0)
Clearly misread the ticket here :(
I'm +1 on the second patch.
comment:10
scribu — 3 years ago
- Keywords tested commit added
Second patch seems to be working as expected.
comment:11
scribu — 3 years ago
is_tax.11904.2.diff validates the taxonomy array upfront, to prevent a very unlikely edge case.
Also reduced the nesting level a bit.
comment:12
dd32 — 3 years ago
- Owner changed from ryan to dd32
- Status changed from assigned to reviewing
comment:13
dd32 — 3 years ago
- Resolution set to fixed
- Status changed from reviewing to closed
comment:14
dd32 — 3 years ago
I removed most of the nesting and seperated it into 2 branches.
re-open if anyone can see a mistake in the conversion.
comment:15
dd32 — 3 years ago
comment:16
dd32 — 3 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
Re-opening, I've reverted part of this, allowing is_tax() return true for Tags and Categories has side effects where core expects is_Tax() to be false for those taxonomies.
Whilst i agree that Tags and categories should return true, More work needs to be done to make it compatible with the rest of core.
comment:17
scribu — 3 years ago
- Resolution set to fixed
- Status changed from reopened to closed
I think the original goal of this ticket has been reached.
We should open a new monster ticket named "Treat categories and tags like regular taxonomies" :)

Attached patch adds conditional is_tax_term([taxonomy], [term]).
Tested with custom taxonomies, categories, and post tags.