[wp-trac] [WordPress Trac] #56327: Correct returntype for `wp_get_object_terms()`

WordPress Trac noreply at wordpress.org
Wed Aug 3 03:08:06 UTC 2022


#56327: Correct returntype for `wp_get_object_terms()`
--------------------------+-----------------------------
 Reporter:  dd32          |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Taxonomy      |    Version:
 Severity:  normal        |   Keywords:
  Focuses:  docs          |
--------------------------+-----------------------------
 Currently the `wp_get_object_terms()` function and the `get_object_terms`
 / `wp_get_object_terms` filters specify that the return value is
 `WP_Term[]` or `WP_Term[] | WP_Error`, but that's not correct.

 `wp_get_object_terms()` ultimately wraps `get_terms()` and per the `$args`
 that are passed through, accepts a `field` value which is best described
 by
 [https://developer.wordpress.org/reference/classes/wp_term_query/__construct/#:~:text=Term%20fields%20to%20query%20for
 WP_Term_Query::__construct()].

 As a result, the data-type is better described by the return value of
 `get_terms()`: `WP_Term[]|int[]|string[]|string|WP_Error`. If one assumes
 the current documentation, you'll likely run into fatal errors when the
 calling code expected it to be `int[]` or `string[]`.

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


More information about the wp-trac mailing list