WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#30620 closed enhancement (fixed)

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

Reported by: joehoyle Owned by: 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 5 years ago.
30620.2.diff (2.1 KB) - added by wonderboymusic 5 years ago.

Download all attachments as: .zip

Change History (12)

#1 @joehoyle
5 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
5 years ago

  • Version set to 3.7

Introduced in [25334].

#4 @helen
5 years ago

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

@wonderboymusic
5 years ago

#5 @wonderboymusic
5 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
5 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
5 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
5 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
5 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.


5 years ago

Note: See TracTickets for help on using tickets.