Make WordPress Core

Opened 10 years ago

Closed 9 years ago

Last modified 9 years ago

#30620 closed enhancement (fixed)

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

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

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 10 years ago.
30620.2.diff (2.1 KB) - added by wonderboymusic 9 years ago.

Download all attachments as: .zip

Change History (12)

#1 @joehoyle
10 years ago

  • Summary changed from get_term_by( 'term_taxonomy_id' ) should require $taxonomy param to get_term_by( 'term_taxonomy_id' ) should NOT require $taxonomy param

#3 @SergeyBiryukov
10 years ago

  • Version set to 3.7

Introduced in [25334].

#4 @helen
10 years ago

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

#5 @wonderboymusic
10 years ago

  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 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
9 years ago

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

If the spirit moves you

#7 @boonebgorges
9 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 34679:

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

Props wonderboymusic.
Fixes #30620.

#8 follow-up: @rmccue
9 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
9 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.


9 years ago

Note: See TracTickets for help on using tickets.