[wp-trac] [WordPress Trac] #62842: PHPDoc of get_category() is misleading

WordPress Trac noreply at wordpress.org
Wed Jan 22 08:10:13 UTC 2025


#62842: PHPDoc of get_category() is misleading
-------------------------+-----------------------------
 Reporter:  apermo       |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Taxonomy     |    Version:  4.4
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 Recently I stumbled upon the case that `get_term()` will return an
 instance of `WP_Term` while `get_category()` suggests it will just return
 an `object`. And when I wanted to add strict comparison I was hesitant.

 {{{
 // Results via wp shell from a german project: Allgemein => uncategorized
 > get_category(1)
 = WP_Term {#10541
     +term_id: 1,
     +name: "Allgemein",
     +slug: "allgemein",
     +term_group: 0,
     +term_taxonomy_id: 1,
     +taxonomy: "category",
     +description: "",
     +parent: 0,
     +count: 50,
     +filter: "raw",
     +"cat_ID": 1,
     +"category_count": 50,
     +"category_description": "",
     +"cat_name": "Allgemein",
     +"category_nicename": "allgemein",
     +"category_parent": 0,
   }

 > get_term(1,'category')
 = WP_Term {#10553
     +term_id: 1,
     +name: "Allgemein",
     +slug: "allgemein",
     +term_group: 0,
     +term_taxonomy_id: 1,
     +taxonomy: "category",
     +description: "",
     +parent: 0,
     +count: 50,
     +filter: "raw",
   }

 }}}

 First of all, I think we should fix the PHPDoc, and I will open a PR for
 that.

 Additionally I want to spark the discussion to either add WPCS rules to
 discourage the use of the aliases or maybe just mark `get_category()` as
 deprecated in favor of `get_term( $term, 'category' )`.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/62842>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list