[wp-trac] [WordPress Trac] #33369: Cannot intelligently target using the `get_terms_args` filter

WordPress Trac noreply at wordpress.org
Thu Aug 13 23:53:30 UTC 2015


#33369: Cannot intelligently target using the `get_terms_args` filter
-----------------------------+-----------------------------
 Reporter:  johnjamesjacoby  |      Owner:
     Type:  feature request  |     Status:  new
 Priority:  normal           |  Milestone:  Awaiting Review
Component:  Taxonomy         |    Version:  2.2
 Severity:  normal           |   Keywords:
  Focuses:                   |
-----------------------------+-----------------------------
 I'm filtering `get_terms_args` in the `get_terms()` function, but because
 I cannot see what the original `$args` parameter was that was passed into
 `get_terms()`, I cannot make an educated decision about whether or not my
 plugin should override any default arguments.

 Example code:

 {{{
 add_filter( 'get_terms_args', function( $args, $taxonomies ) {
     if ( 'id' !== $args['orderby'] ) {
         $args['orderby'] = 'id';
     }
     return $args;
 } ), 10, 2 );
 }}}

 The above snippet will always force `get_terms()` to order by `id` which
 actually isn't what I want to do. I want to only order by `id` if the
 `orderby` passed into `get_terms()` was not `id`.

 This happens because of the following code in `get_terms()`
 {{{
 $args = wp_parse_args( $args, $defaults );
 }}}

 Not an unusual line (over 80 other occurrences in core) but it's not ideal
 because it overwrites the original `$args` parameter, and filters cannot
 compare the two variables to make more intelligent decisions.

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


More information about the wp-trac mailing list