Sort Category list by meta key

July 31, 2021

If you want to sort your category list by meta key you can use the following code

$temp=get_categories(
                array( 'parent' => $parent_id

                 )
            );


 $sorted_cats = array();
 foreach($temp as $cat){
               // $ordr = get_field('display_order', 'category_'.$cat>term_id);
                $sort_order = get_term_meta($cat->term_id, '_sortorder', true);
                $categories[$sort_order] = $cat;
 }
ksort($categories);