Make WordPress Core

Opened 12 years ago

Closed 11 years ago

Last modified 11 years ago

#30620 closed enhancement (fixed)

get_term_by( 'term_taxonomy_id' ) should NOT require $taxonomy param

Reported by: joehoyle Owned by: boonebgorges
Priority: normal Milestone: 4.4
Component: Taxonomy Version: 3.7
Severity: normal Keywords: has-patch
Cc: Focuses:

Description

As we all despise term_ids as it requires a id / taxonomy name pair, it's often nicer to use term_taxonomy_id as it's a much better identifier. This *should* mean it's not necessary to know the taxonomy of a given tt_id (just like one doesn't need to know the post_type of a post to get a post from ID). However, the $taxonomy param to get_term_by() is required.

It seems to be it would be good to change $taxonomy to be not required in the cases of getting by tt_id with get_term_by().

I'll write the code if anyone agrees this makes sense :)

Apologies if that has ben addresses, I'm a bit out of the loop recently.

Attachments (2)

30620.diff​ (2.1 KB ) - added by wonderboymusic 12 years ago.
30620.2.diff​ (2.1 KB ) - added by wonderboymusic 11 years ago.

Download all attachments as: .zip

Change History (12)

#1 @joehoyle
12 years ago

  • Summary get_term_by( 'term_taxonomy_id' ) should require $taxonomy param → get_term_by( 'term_taxonomy_id' ) should NOT require $taxonomy param

#3 @SergeyBiryukov
12 years ago

  • Version → 3.7

Introduced in [25334].

#4 @helen
12 years ago

It appears I agreed with this a while ago, wonderboymusic pointed out that we should mind the cache (see #21760).

#5 @wonderboymusic
12 years ago

  • Keywords has-patch added
  • Milestone Awaiting Review → Future Release

30620.diff​ - we would probably need to add tt_ids to a cache that is does not have tax in its group hash

#6 @wonderboymusic
11 years ago

  • Milestone Future Release → 4.4
  • Owner set to boonebgorges
  • Status new → assigned

If the spirit moves you

#7 @boonebgorges
11 years ago

  • Resolution → fixed
  • Status assigned → closed

In 34679:

Don't require explicit taxonomy when getting terms by term_taxonomy_id.

Props wonderboymusic.
Fixes #30620.

#8 follow-up: @rmccue
11 years ago

FYI, this change to get_term_by ​broke the REST API, since we relying on the check. We've fixed it, but might be worth noting in a field notes post for others that it might break.

(Accidentally commented on #14162, but that's unrelated.)

#9 in reply to: ↑ 8 @boonebgorges
11 years ago

Replying to rmccue:

FYI, this change to get_term_by ​broke the REST API, since we relying on the check. We've fixed it, but might be worth noting in a field notes post for others that it might break.

(Accidentally commented on #14162, but that's unrelated.)

Thanks for the note. I'll note the change in the taxonomy field notes for 4.4. But the new behavior is probably the correct one: if you are passing a 'term_taxonomy_id', you're likely doing it for the explicit reason that you want to avoid the 'taxonomy' table join, which means that you've already done your homework.

This ticket was mentioned in ​Slack in #core-restapi by boone. ​View the logs.


11 years ago

Note: See TracTickets for help on using tickets.