Custom Sort Categories with ACF

Template layouts (and client requests) will often require a list of categories to be laid out in a specific order to draw attention to different content.

Add a numbered “order” field to your categories using Advanced Custom Fields and sort through the categories using the following:

$categories = get_categories( $args );  

usort($categories, function($a, $b) {
   return get_field("category_order", "category_".$a->term_id) - get_field("category_order", "category_".$b->term_id);
});

foreach ($categories as $category){

Sourced here.

Leave a Reply

katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.