Make WordPress Core

Opened 6 years ago

Closed 4 years ago

Last modified 4 years ago

#45163 closed enhancement (fixed)

get_term_by() should accept ID as a field

Reported by: emrikol's profile emrikol Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 5.5 Priority: normal
Severity: normal Version:
Component: Taxonomy Keywords: has-patch has-unit-tests 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 6 years ago.
Patch against trunk for get_term_by
45163_unittest.patch (624 bytes) - added by esoj 4 years ago.
Unittest for this issue
45163.patch (1.3 KB) - added by esoj 4 years ago.
A simplified approach and updated documentation.

Download all attachments as: .zip

Change History (14)

@emrikol
6 years ago

Patch against trunk for get_term_by

#1 @SergeyBiryukov
6 years ago

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

@esoj
4 years ago

Unittest for this issue

@esoj
4 years ago

A simplified approach and updated documentation.

#2 @esoj
4 years ago

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

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


4 years ago

#4 @noisysocks
4 years ago

  • Milestone changed from Future Release to 5.5

#5 @SergeyBiryukov
4 years ago

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

#6 @whyisjake
4 years 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
4 years ago

In 47866:

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

See: #45163.
Props: whyisjake.

#8 @ocean90
4 years 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
4 years 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 4 years ago by SergeyBiryukov (previous) (diff)

#10 @SergeyBiryukov
4 years 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.

#11 @SergeyBiryukov
4 years ago

  • Keywords revert removed
  • Resolution set to fixed
  • Status changed from reopened to closed

Closing as no other objections were raised and 5.5 Beta 1 is planned for today.

If someone feels strongly about reverting [47865] based on comment:8, feel free to reopen.

Last edited 4 years ago by SergeyBiryukov (previous) (diff)
Note: See TracTickets for help on using tickets.