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

WordPress Trac noreply at wordpress.org
Fri Aug 14 01:47:51 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                 |  Resolution:
 Keywords:  has-patch 2nd-opinion  |     Focuses:

Comment (by johnjamesjacoby):

 > It could be argued that a function using defaults should return the same
 result when the argument was explicit and equal to the default, as when
 (deliberately) omitted. My trust in the documentation of a function would
 be damaged if I found this not to be true.
 If I understand you correctly, I don't think this is true. See
 `get_tags()` for a (maybe poor) example of this:

 $r = apply_filters( 'get_media_item_args', $args );

 > In other words, I think `get_terms( 'mytax', array( 'orderby' => 'name'
 ) )` and `get_terms( 'mytax' )` should return the same results when called
 in the same context, regardless of any filter.
 I disagree. The reason filters exist is to allow for overriding the
 environment and it's relative variables.

 > That is why I'm not sure that filters really should be informed on how
 the arguments was given, only their value after merging with defaults. The
 way WordPress uses `wp_parse_args()` resembles that of PHP when using
 optional arguments.
 I understand. And I am positive that most of WordPress core operates this

 > Do you have a use case where this "knowledge" is the only way to do what
 you want?
 See above. In this case, which might be unique, there is a default
 `orderby` of `name` in the defaults, which gets transferred to `$args` if
 none are passed. That funnels into the `get_terms_orderby` filter, which
 includes the query clause and the `$args` array, but `orderby` is never
 empty unless it's explicitly passed as such, so it's not possible to
 conditionally filter it.

 > Are there any other filters in core that reveals the arguments as given
 before defaulting?
 `get_media_item_args` and `wp_link_pages_args` are the two that I found at
 a cursory. FWIW, most of BuddyPress's & bbPress's template tags works this
 way, to allow JIT manipulating of return values based on both the merged
 arguments and the original ones. Basically, the more relevant data that's
 passed into a filter is the more useful it is.


 One other way to maybe approach this would be to remove all references to
 `'orderby' => 'name'` from relative `get_terms()` usages, or remove the
 default `t.name` (if `orderby` somehow ends up empty) with some uniquely
 filterable value.

 Ultimately, there's no way to know if `t.name` was the intended query
 argument passed into the function, or the default fallback because no
 `orderby` argument was passed. Which is also to say, there's no way to
 override `t.name` without accidentally doing it almost everywhere all the

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

More information about the wp-trac mailing list