#15407 closed defect (bug) (fixed)
get_the_category code duplication
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 3.1 |
| Component: | Taxonomy | Version: | 3.1 |
| Severity: | normal | Keywords: | has-patch |
| Cc: | westi |
Description
get_the_category needlessly duplicates the functionality of get_the_terms, and it lacks a filter that the corresponding get_the_tags has.
Attachments (4)
Change History (25)
Well, my thought was to be consistent with get_the_tags, so that the general form would be get_the_[taxonomy]s
The function itself, get_the_category(), is rather poorly named.
How about we deprecate get_the_category() and add a get_the_categories() then?
deprecate-get_the_category.15407.diff deprecates and replaces get_the_category().
comment:6
automattor — 3 years ago
- Resolution set to fixed
- Status changed from new to closed
- Resolution fixed deleted
- Status changed from closed to reopened
For consistency, the_category() with the_categories()?
These are very commonly used template tags so I'm not sure deprecating them for a pluralization is worth it. We've been fine for 8+ major releases with them as is.
I'm not wedded to the name change, but I think the code duplication fix of the original patch should stay.
I also think that get_the_categories as a filter makes more sense than get_the_category or the like, because it's filtering an array.
And actually, maybe it wouldn't be a bad idea to go with the_categories(). It's easier to remember, and the Extend theme reviewers will love having the_category() deprecated so they can smite even more themes. :)
comment:10
westi — 3 years ago
- Cc westi added
- Keywords revert added
The name change needs to be reverted - we should and will not rename a function just for the sake of the name being more proper.
comment:11
westi — 3 years ago
- Resolution set to fixed
- Status changed from reopened to closed
comment:12
follow-up:
↓ 14
Denis-de-Bernardy — 3 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
The newly introduced filter's name is plural and inconsistent with the function's name. Suggesting we rename it accordingly.
comment:13
filosofo — 3 years ago
It makes more sense to name a filter according to the use of the filter rather than its containing function, especially when the function is poorly named.
comment:14
in reply to:
↑ 12
westi — 3 years ago
- Resolution set to fixed
- Status changed from reopened to closed
Replying to Denis-de-Bernardy:
The newly introduced filter's name is plural and inconsistent with the function's name. Suggesting we rename it accordingly.
This is intentional.
comment:15
nacin — 3 years ago
comment:16
nacin — 3 years ago
- Keywords revert removed
- Resolution fixed deleted
- Status changed from closed to reopened
After an IRC discussion with Viper007Bond, the issue here is that get_the_terms() may return false. I was trying to prevent issues there, but it may be cast awkwardly into an array(0=>null) which then causes some problems.
Shuffling things around here a bit.
comment:17
nacin — 3 years ago
- Resolution set to fixed
- Status changed from reopened to closed
Viper007Bond — 3 years ago
comment:18
Viper007Bond — 3 years ago
Whoops, I guess you saw my message in IRC before you timed out. :)
comment:19
ryan — 3 years ago
comment:20
gazouteast — 2 years ago
I struggled to follow this one - are you saying that get_the_category() and the_category() are now deprecated?
comment:21
nacin — 2 years ago
No. They were deprecated, then undeprecated.

Shouldn't the filter be named 'get_the_category' ?