Opened 3 years ago

Closed 3 years ago

#11904 closed enhancement (fixed)

Conditional tag for terms

Reported by: pavelevap Owned by: dd32
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)

is_tax_term.11904.diff (1.3 KB) - added by filosofo 3 years ago.
is_tax.11904.diff (2.1 KB) - added by filosofo 3 years ago.
is_tax.11904.2.diff (2.1 KB) - added by scribu 3 years ago.
better taxonomy validation

Download all attachments as: .zip

Change History (20)

  • Type changed from feature request to enhancement
  • Owner set to filosofo
  • Status changed from new to assigned
  • Component changed from General to Taxonomy
  • Keywords has-patch added
  • Owner changed from filosofo to ryan

Attached patch adds conditional is_tax_term([taxonomy], [term]).

Tested with custom taxonomies, categories, and post tags.

comment:4 follow-up: ↓ 5   scribu3 years ago

I don't think $term should be optional.

comment:5 in reply to: ↑ 4   filosofo3 years ago

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);
}

comment:6 follow-up: ↓ 8   scribu3 years ago

How about we add $term as an optional parameter to is_tax(), directly?

It seems more intuitive.

comment:7 follow-up: ↓ 9   nacin3 years ago

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?

comment:8 in reply to: ↑ 6   filosofo3 years ago

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.

comment:9 in reply to: ↑ 7   nacin3 years ago

function is_term($term, $taxonomy = '', $parent = 0)

Clearly misread the ticket here :(

I'm +1 on the second patch.

  • Keywords tested commit added

Second patch seems to be working as expected.

scribu3 years ago

better taxonomy validation

is_tax.11904.2.diff validates the taxonomy array upfront, to prevent a very unlikely edge case.

Also reduced the nesting level a bit.

  • Owner changed from ryan to dd32
  • Status changed from assigned to reviewing
  • Resolution set to fixed
  • Status changed from reviewing to closed

(In [13486]) More powerful version is is_tax(). Props filosofo, scribu. Adds $term parameter. Fixes #11904

I removed most of the nesting and seperated it into 2 branches.

re-open if anyone can see a mistake in the conversion.

(In [13495]) Revert part of r13486, is_tax() is false for tags
categories. See #11904
  • 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.

  • 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" :)

Note: See TracTickets for help on using tickets.