[wp-trac] [WordPress Trac] #21760: get_term_by() calls are not cached

WordPress Trac noreply at wordpress.org
Fri Dec 2 21:21:48 UTC 2016


#21760: get_term_by() calls are not cached
-------------------------------------------------+-------------------------
 Reporter:  wonderboymusic                       |       Owner:  ocean90
     Type:  enhancement                          |      Status:  reopened
 Priority:  normal                               |   Milestone:  4.7
Component:  Taxonomy                             |     Version:  2.3
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch needs-testing has-unit-    |     Focuses:
  tests                                          |  performance
-------------------------------------------------+-------------------------
Changes (by dd32):

 * keywords:  has-patch needs-testing has-unit-tests commit => has-patch
     needs-testing has-unit-tests


Comment:

 Okay, so after looking through this, [38677] has to be reverted from the
 4.7 branch, and either something put in place for trunk/4.8 or reverted
 there too (not immediately though).

 Since it's not mentioned, here's a minimal example of the breakage (there
 are other ways of triggering it, but this is the most direct)
 {{{
 add_filter( 'get_terms', function( $terms ) {

         get_term_by( 'slug', 'foo', 'category' );

         return $terms;
 } );

 get_term_by( 'slug', 'foobar-ugh', 'category' );
 }}}

 I'll admit that using term functions within term filters seems like a bad
 idea - something is going to break eventually - unfortunately though, it's
 worked, and filtering terms has become a very popular thing to do.

 There's options for fixing this, the most obvious one is adding an `$arg`
 to `get_terms()` to skip running the `get_terms` filter - such as
 `$args['suppress_filters']`, which would also need to apply to
 `WP_Term_Query` IMHO. Doing that feels hacky though.

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


More information about the wp-trac mailing list