WordPress.org

Make WordPress Core

Opened 21 months ago

Last modified 5 weeks ago

#45163 reopened enhancement

get_term_by() should accept ID as a field

Reported by: emrikol Owned by: SergeyBiryukov
Milestone: 5.5 Priority: normal
Severity: normal Version:
Component: Taxonomy Keywords: has-patch has-unit-tests revert 2nd-opinion
Focuses: Cc:

Description

Similar to ticket #33869 and get_user_by(), get_term_by() should accept either ID or id for the $field argument.

This helps keep consistency between similar functions that use similar arguments.

Attachments (3)

get_term_by_ID.patch (650 bytes) - added by emrikol 21 months ago.
Patch against trunk for get_term_by
45163_unittest.patch (624 bytes) - added by esoj 2 months ago.
Unittest for this issue
45163.patch (1.3 KB) - added by esoj 2 months ago.
A simplified approach and updated documentation.

Download all attachments as: .zip

Change History (13)

@emrikol
21 months ago

Patch against trunk for get_term_by

#1 @SergeyBiryukov
21 months ago

  • Component changed from General to Taxonomy
  • Keywords has-patch needs-unit-tests added
  • Milestone changed from Awaiting Review to Future Release

@esoj
2 months ago

Unittest for this issue

@esoj
2 months ago

A simplified approach and updated documentation.

#2 @esoj
2 months ago

  • Keywords has-unit-tests added; needs-unit-tests removed

This ticket was mentioned in Slack in #core by esoj. View the logs.


2 months ago

#4 @noisysocks
2 months ago

  • Milestone changed from Future Release to 5.5

#5 @SergeyBiryukov
2 months ago

  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

#6 @whyisjake
5 weeks ago

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

In 47865:

Taxonomy: Extend get_term_by to accept ID as a term parameter.

Similar to get_user_by, both ID and id should be able to accepted.

Fixes #45163.
Props emrikol, esoj.

#7 @whyisjake
5 weeks ago

In 47866:

Code Standards: Clean up whitespace on the end of a file.

See: #45163.
Props: whyisjake.

#8 @ocean90
5 weeks ago

  • Keywords revert added
  • Resolution fixed deleted
  • Status changed from closed to reopened
  • Type changed from defect (bug) to enhancement

Unlike the users and posts table, the terms table has no ID column. From that point it doesn’t make sense to adopt the behavior from the other functions. Since terms have actually two IDs we shouldn’t really promote another alias for an existing alias id for term_id.

Voting for a revert of [47865].

#9 @SergeyBiryukov
5 weeks ago

  • Keywords 2nd-opinion added

Indeed, id is already an alias for term_id here, and ID is now a second alias. While that seems a bit redundant, it adds some consistency between the APIs despite the underlying database structure differences. I can see it both ways and don't necessarily object to the change. Would appreciate more opinions here.

The documentation, however, needs some adjustment for consistency with that of get_user_by().

Last edited 5 weeks ago by SergeyBiryukov (previous) (diff)

#10 @SergeyBiryukov
5 weeks ago

In 47870:

Docs: Adjust the documentation for the new ID alias in get_term_by() for consistency with get_user_by().

Follow-up to [47865].

See #45163.

Note: See TracTickets for help on using tickets.