I would like to know if it is possible in WordPress admin to show categories in post-new.php
and edit-tags.php?taxonomy=category
sorted by id NOT by category name.
1 Answer
The following should work…
add_action('get_terms_args','my_order_cats',10,2);
function my_order_cats($args,$taxonomies){
//Check we are admin side
if(is_admin()){
$taxonomy = $taxonomies[0];
$screen = get_current_screen();
//Check screen ID and taxonomy and changes $args where appropriate.
if(($screen->id=='edit-category'||$screen->id=='post') && $taxonomy=='category'){
$args['orderby']='id'; //preserves order of subcategories.
$args['order']='asc'; //or desc
}
}
return $args;
}
It preserves the order of subcategories (i.e. children always appear below their parents regarldless if order is set to ASC/DESC).
This could be adapted for custom taxonomies, you would simply need to chhange the $screen->ID
and $taxonomy
checks.