5

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

5

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

    enter image description here

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

  • Thank you very much! [in addition to those plugins, I also wrote a short code that performs categories in tree veiw] – Shimon S May 25 '12 at 7:25
  • I wonder, how can I show a particular term on the top? – Shimon S May 25 '12 at 8:06
  • Maybe, the easiest way would be jQuery DOM manipulation, check this answer for inspiration :) – brasofilo May 25 '12 at 8:20
  • @s976 - forgot to tag you in my previous comment... scribu's plugin, CCT, has some jQuery to auto-scroll the list, you can get some ideas from there too. – brasofilo May 25 '12 at 9:42
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.

  • This was a exactly what I was looking for and it works fine for custom taxonomies too, just change 'category_' to the name of your taxonomy. – Thomas Bindzus Jul 1 '17 at 11:14
-1

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/
  • I think that you sugestion is for users side. And I am looking for how to change the order on a admin side. – Shimon S May 24 '12 at 10:52
  • Both of those suggestions are for admins. Users really shouldn't have any access to the theme files, and if you look at the instructions for the plugin, it's clearly talking about admin use. – user1337 May 24 '12 at 15:26
  • @user1337 - you are confusing the user "admin" (or having administrative powers over a site) with WordPress backend, also referred as Admin or Dashboard. – brasofilo May 24 '12 at 19:30
  • @brasofilo - Not at all. Either the user "admin" or someone who has plugin access to the admin or dashboard can install that plugin and change the order that categories are listed in. One can also use a roles plugin to delegate that ability to other roles beside the administrator. – user1337 May 24 '12 at 19:57
  • Will the plugin work in this meta box? – brasofilo May 24 '12 at 20:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.