[wp-trac] [WordPress Trac] #37198: Use `WP_Term_Query` for `wp_get_object_terms()`

WordPress Trac noreply at wordpress.org
Mon Jun 27 11:19:43 UTC 2016


#37198: Use `WP_Term_Query` for `wp_get_object_terms()`
-----------------------------+------------------------------
 Reporter:  flixos90         |       Owner:
     Type:  enhancement      |      Status:  new
 Priority:  normal           |   Milestone:  Awaiting Review
Component:  Taxonomy         |     Version:  trunk
 Severity:  normal           |  Resolution:
 Keywords:  early has-patch  |     Focuses:
-----------------------------+------------------------------
Changes (by flixos90):

 * keywords:  needs-patch early => early has-patch


Comment:

 I played around with this to create a first draft for a patch in
 [attachment:37198.diff].

 In addition to conditionally adding the necessary JOIN statement (only
 when object IDs are passed), there were some additional tweaks necessary
 as several things that used to happen in `get_terms()` (and now
 `WP_Term_Query`) were not applicable / compatible with how
 `wp_get_object_terms()` work. Therefore I include checks for whether
 `object_ids` is empty or not in several locations to be backwards-
 compatible.

 Also, new values for the `fields` argument are supported as needed for
 `wp_get_object_terms()` (`all_with_object_id`, `tt_ids`, `slugs`).

 There is a new private method `post_process_terms` which is used to ensure
 that the terms are sanitized if object IDs are passed
 (`wp_get_object_terms()` expects sanitized data). This method is not only
 run after doing the SQL query, but also after retrieving cached results.

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


More information about the wp-trac mailing list