[wp-trac] [WordPress Trac] #42005: filter get_terms_args and orderby meta_value_num not working as expected

WordPress Trac noreply at wordpress.org
Wed Sep 27 08:15:19 UTC 2017


#42005: filter get_terms_args and orderby meta_value_num not working as expected
--------------------------------+-----------------------------
 Reporter:  Fred_Bdx            |      Owner:
     Type:  feature request     |     Status:  new
 Priority:  normal              |  Milestone:  Awaiting Review
Component:  Taxonomy            |    Version:  4.8.2
 Severity:  normal              |   Keywords:
  Focuses:  ui, administration  |
--------------------------------+-----------------------------
 This is a follow-up to #34996.

 Hi,

 this is working :
 {{{#!php
 <?php
 add_filter( 'get_terms_defaults', 'my_get_terms_defaults', 10, 2 );
 function my_get_terms_defaults( $defaults, $taxonomies ) {
         if ( in_array( 'my_tax_types', $taxonomies ) ) {
                 $defaults['orderby']            = 'meta_value_num';
                 $defaults['meta_key']   = 'tax_position';
         }
         return $defaults;
 }
 }}}

 this is working too (for example) :
 {{{#!php
 <?php
 add_filter( 'get_terms_args', 'my_get_terms_args', 10, 2 );
 function my_get_terms_args( $args, $taxonomies ) {
         if ( in_array( 'my_tax_types', $taxonomies ) ) {
                 $args['orderby']        = 'name';
                 $args['order']          = 'DESC';
         }
         return $args;
 }
 }}}

 BUT this is NOT working :
 {{{#!php
 <?php
 add_filter( 'get_terms_args', 'my_get_terms_args', 10, 2 );
 function my_get_terms_args( $args, $taxonomies ) {
         if ( in_array( 'my_tax_types', $taxonomies ) ) {
                 $args['orderby']        = 'meta_value_num';
                 $args['meta_key']       = 'tax_position';
         }
         return $args;
 }
 }}}


 As Samuel said here : https://wordpress.org/support/topic/filter-
 get_terms_args-and-orderby-meta_value_num-not-working/#post-9533065 , is
 it possible to move earlier in the process the get_terms_args filter ?

 Because for now, the get_terms_defaults filter doesn't apply on all
 returned get_terms(), the get_terms_args filter does, but not accept
 orderby meta_value_num.

 Thanks.

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


More information about the wp-trac mailing list