Monday, August 8, 2022
HomeWordPress Developmentphrases - get_terms_args ordering by meta key not working

phrases – get_terms_args ordering by meta key not working


I’ve a customized taxonomy referred to as “version”. Every version has a meta key “_edition” that shops an incremental quantity from 1 to N. So, if I’ve an version referred to as “Version 13”, it can retailer “_edition” meta key with worth of 13.

My query is: I am making an attempt to order my phrases in admin with this “_edition” meta key. To realize that, I am making an attempt to make use of the “get_terms_args” filter, this fashion:

add_filter("get_terms_args", "MyTheme_GetTermsArgs", 10, 2);

operate MyTheme_GetTermsArgs($args, $taxonomies)
{
    if(is_admin() && in_array("version", $taxonomies)){
        $args['orderby'] = "meta_value_num";
        $args['meta_key'] = "_edition";
        $args['order'] = "DESC";
    }
    
    return $args;
}

However the ensuing order could be very unusual. There are round 123 editions, and the consequence ordering is

1, 2, 3, […], 8, 9, 10, 100, 101, 102, 103, […], 109, 11, 110, 111, 112, 113, […], 118, 119, 12, 120, 121, 122, 123, 13, 14, 15, 16 […].

The anticipated is a “regular” ordering from 1 to 123. I’ve already tried altering “orderby” to “meta_value”, specifying an “meta_type”. All with out success.

Can somebody assist me?

Thanks!

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments