Wordpress - How to Change the Categories Order in the Admin Dashboard?
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
Gecka Terms Ordering : creates an auxiliary table in the database (
wp_termmeta
) to deal with the ordering. Has drag and drop capabilities.
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.