terms – get_terms_args ordering by meta key not working

Question

I have a custom taxonomy called “edition”. Each edition has a meta key “_edition” that stores an incremental number from 1 to N. So, if I have an edition called “Edition 13”, it will store “_edition” meta key with value of 13.

My question is: I’m trying to order my terms in admin with this “_edition” meta key. To achieve that, I’m trying to use the “get_terms_args” filter, this way:

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

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

But the resulting order is very strange. There are around 123 editions, and the result 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 expected is a “normal” ordering from 1 to 123. I’ve already tried changing “orderby” to “meta_value”, specifying an “meta_type”. All without success.

Can someone help me?

Thanks!

0
RBFraphael 2 months 2022-08-08T11:13:35-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse