🌱 Wordpress - custom sort order

Get terms from WordPress and sort in custom order

// get cateogries
$features = get_the_terms($post->ID,'feature');

// sort features in this order 'branch', 'atm', 'trust-department'
// yes it looks backwards but they echo out in reverse order in the template
$sortOrder = array_flip(array('trust-department', 'atm', 'branch'));
usort($features, function($x, $y) use($sortOrder) {
    return $sortOrder[$x->slug] - $sortOrder[$y->slug];
});
Made by Brandon . If you find this project useful you can donate.