WordPress.org

Make WordPress Core

Opened 2 years ago

#42005 new feature request

filter get_terms_args and orderby meta_value_num not working as expected

Reported by: Fred_Bdx Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.8.2
Component: Taxonomy Keywords:
Focuses: ui, administration Cc:
PR Number:

Description

This is a follow-up to #34996.

Hi,

this is working :

<?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
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
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.

Change History (0)

Note: See TracTickets for help on using tickets.