[wp-trac] [WordPress Trac] #57131: get_the_terms(): Parameter #1 ($post) of type is nullable.

WordPress Trac noreply at wordpress.org
Thu Nov 17 16:12:11 UTC 2022


#57131: get_the_terms(): Parameter #1 ($post) of type is nullable.
-------------------------+------------------------------
 Reporter:  omaeyusuke   |       Owner:  (none)
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  Taxonomy     |     Version:  3.6
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |     Focuses:  docs
-------------------------+------------------------------

Comment (by SergeyBiryukov):

 Hi there, welcome back to WordPress Trac! Thanks for the ticket and the
 PR.

 Looking at the other taxonomy functions, including
 `get_the_category_list()`, `in_category()`, `the_category()`,
 `has_category()`, `has_term()`, etc., it seems like we don't generally
 include `null` as an accepted value for the optional `$post` or `$post_id`
 parameter, but we do note "Defaults to the current post".

 For `get_the_terms()` function it's a bit different because, unlike in the
 above functions, the `$post` parameter is required, not optional.

 I'm not quite sure about this change. While technically `$post` can be
 `null` here, passing the ID explicitly as the current documentation
 suggests seems more readable and future-proof:
 {{{
 $term = get_the_terms( get_the_ID(), 'category' );
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/57131#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list