Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save drdogbot7/8ad1383242793cd3eab9dcc00f23bb01 to your computer and use it in GitHub Desktop.
Save drdogbot7/8ad1383242793cd3eab9dcc00f23bb01 to your computer and use it in GitHub Desktop.
Sort Wordpress categories by custom field

#Sort Wordpress categories by custom field:

where category_order is a custom field.

$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);
});

thx

or without custom field by using description field

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment