How to Change the Categories Order in the Admin Dashboard?

All we need is an easy explanation of the problem, so here it is.

The order of categories on dashboard is alphabetical. Can I change it to custom order?

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

Found an answer in this answer.

add_filter( 'get_terms_args', 'wpse_53094_sort_get_terms_args', 10, 2 );
function wpse_53094_sort_get_terms_args( $args, $taxonomies ) 
{
    global $pagenow;
    if( !is_admin() || ('post.php' != $pagenow && 'post-new.php' != $pagenow) ) 
        return $args;
    
    $args['orderby'] = 'slug';
    $args['order'] = 'DESC';

    return $args;
}

The order may be ASC or DESC, and the orderby can be:

  • count
  • description (it should, but didn’t work so well for me, futher tests necessary)
  • name
  • slug


Plugins of interest

(may we call those Plinterests?)

The first two are very short and and can be easily incorporated into your code.

  • Category Checklist Expander : expands the height of the category list, so no scrolling is needed

  • Category Checklist Tree : this one rebuilds the Category Meta Box, so you can modify its code for further styling/adapting the box – and here’s a screenshot of what it does

    How to Change the Categories Order in the Admin Dashboard?

  • Gecka Terms Ordering : creates an auxiliary table in the database (wp_termmeta) to deal with the ordering. Has drag and drop capabilities.

Method 2

Use the plugin Advanced Custom Fields (This plugin is handy in many different ways). Then create an custom order field (category_order) with the rule ‘Taxanomy_Term’ is equal to ‘Categories’.

Then in your theme functions.php (or somewhere relevant) use:

$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){
...

Where category_order is the field name you created with ACF.

This post inspired by this one here.

Method 3

There’s no default option for it, but there’s two other ways.

  1. Change it in the theme files http://codex.wordpress.org/Template_Tags/wp_list_categories
  2. Use a plugin. Eg http://wordpress.org/extend/plugins/my-category-order/

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply