[wp-trac] [WordPress Trac] #34175: Add correlating get_fields_terms filter for get_terms

WordPress Trac noreply at wordpress.org
Wed Oct 7 02:30:32 UTC 2015


#34175: Add correlating get_fields_terms filter for get_terms
--------------------------+--------------------------
 Reporter:  wpsmith       |       Owner:
     Type:  defect (bug)  |      Status:  closed
 Priority:  normal        |   Milestone:
Component:  Taxonomy      |     Version:  trunk
 Severity:  normal        |  Resolution:  wontfix
 Keywords:                |     Focuses:  performance
--------------------------+--------------------------
Changes (by boonebgorges):

 * status:  new => closed
 * resolution:   => wontfix
 * milestone:  Awaiting Review =>


Comment:

 `get_terms_fields` was introduced in [11037]. See #9004.

 `get_terms_fields` is an unpleasant filter. It has been juggled around in
 various places in `get_terms()` through the years in such a way that it's
 surprise it works for anyone anymore. I'd like to remove it altogether.
 But there are probably some people who have managed to make it work (after
 a fashion) and they should continue to be able to do so. Anyway, I do not
 want to make a bunch of changes to `get_terms()` just so that people can
 more easily use this old filter, especially when improper use of the
 filter breaks the cache strategy of `get_terms()`.

 Your proposed `get_terms_fields_terms` filter doesn't do anything that you
 couldn't already do by processing the results of `get_terms()` using
 `wp_list_pluck()` or a `foreach` loop. If you need to do it via filter,
 use `'get_terms'`.

 Also, the way the filter is currently placed means that it breaks caching
 in `get_terms()`. Let's say you have the following:

 {{{
 function wp34175_customize_get_terms_output( $terms ) {
     if ( is_page() ) {
         return wp_list_pluck( $terms, 'name' );
     } else {
         return $terms;
     }
 }
 add_filter( 'get_terms_fields_terms', 'wp34175_customize_get_terms_output'
 );
 }}}

 If you call it first on a page, the value added to the cache will be an
 array of names. If you later call it outside of a page context using the
 same params, you'll be given the same array of names, even though you
 wanted term objects.

 For more background on the relationship between `'get_terms_fields'`, the
 `fields` param, and the `get_terms()` cache, see #31174. In the meantime,
 for your purposes, use the `get_terms` filter.

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


More information about the wp-trac mailing list