• Hello,

    I am trying to get sorted terms filtered by custom term meta.

        $parent_term_id = 60;
        $cat_args = array(
            'parent' => $parent_term_id,
            'orderby' => 'DATE',
            'order' => 'ASC',
            'meta_key' => 'created',
            'meta_type' => 'DATE'
        );
        $terms =  get_terms('product_cat', $cat_args);

    I got these terms filtered and it returns only with ‘created’ meta value. However, if I print term meta values (‘created’), I got

    
    [“2021-12-20”][“2021-11-03”][“2022-05-03”][“2022-02-18”][“2021-11-26”][“2020-10-27”]

    Which is not ordered by date. What is wrong in my query?

Viewing 1 replies (of 1 total)
  • When you are telling the query how to order, there’s no value for ‘DATE’ to oder by. What you are trying to order by is a meta value, not a term value (terms don’t have datesby default, so you can’t just order by date anyway).

    Looking at the proper arguments for that function, you want to order by ‘meta_value’:

    $cat_args = array(
        'parent' => $parent_term_id,
        'orderby' => 'meta_value', // May also be meta_value_num if the values are numeric
        'order' => 'ASC',
        'meta_key' => 'created',
        'meta_type' => 'DATE'
       );
Viewing 1 replies (of 1 total)
  • The topic ‘WP terms doesn’t sort’ is closed to new replies.