Make WordPress Core

Opened 15 years ago

Closed 15 years ago

#11904 closed enhancement (fixed)

Conditional tag for terms

Reported by: pavelevap's profile pavelevap Owned by: dd32's profile dd32
Milestone: 3.0 Priority: normal
Severity: normal Version: 2.9.1
Component: Taxonomy Keywords: has-patch tested commit
Focuses: Cc:

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 15 years ago.
is_tax.11904.diff (2.1 KB) - added by filosofo 15 years ago.
is_tax.11904.2.diff (2.1 KB) - added by scribu 15 years ago.
better taxonomy validation

Download all attachments as: .zip

Change History (20)

#1 @scribu
15 years ago

  • Type changed from feature request to enhancement

#2 @filosofo
15 years ago

  • Owner set to filosofo
  • Status changed from new to assigned

#3 @filosofo
15 years ago

  • 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.

#4 follow-up: @scribu
15 years ago

I don't think $term should be optional.

#5 in reply to: ↑ 4 @filosofo
15 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);
}

#6 follow-up: @scribu
15 years ago

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

It seems more intuitive.

#7 follow-up: @nacin
15 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?

#8 in reply to: ↑ 6 @filosofo
15 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.

#9 in reply to: ↑ 7 @nacin
15 years ago

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

Clearly misread the ticket here :(

I'm +1 on the second patch.

#10 @scribu
15 years ago

  • Keywords tested commit added

Second patch seems to be working as expected.

@scribu
15 years ago

better taxonomy validation

#11 @scribu
15 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.

#12 @dd32
15 years ago

  • Owner changed from ryan to dd32
  • Status changed from assigned to reviewing

#13 @dd32
15 years ago

  • 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

#14 @dd32
15 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.

#15 @dd32
15 years ago

(In [13495]) Revert part of r13486, is_tax() is false for tags
categories. See #11904

#16 @dd32
15 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.

#17 @scribu
15 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" :)

Note: See TracTickets for help on using tickets.