Quickly and easily reorder taxonomy terms with an easy to use and intuitive drag and drop interface.
- Install and activate the plugin
- If you need to enable term sorting on default WordPress taxonomies, please see below.
- If you would like to enable taxonomy term sorting on custom post type taxonomies, please see below.
- Once enabled, you can drag & drop re-order your taxonomy terms. Whenever 'get_terms()' is used to display your terms, they will display in the order you've set.
After installing and activating the plugin, you have two options. You can enable drag & drop on any of the default taxonomies. To enable drag & drop sorting on default WordPress taxonomies, you'll want to assign the tax_position
parameter to the register_post_type call.
The easiest way to do so, is to use the following snippet.
/*
* Enable drag & drop sorting on default WordPress taxonomies (ie: categories) - (page/post)
*/
add_filter( 'register_taxonomy_args' , 'add_tax_position_support', PHP_INT_MAX, 3 );
function add_tax_position_support( $args, $taxonomy, $object_type ) {
if( 'category' == $taxonomy ) { // Change the name of the taxonomy you want to enable drag&drop sort on
$args['tax_position'] = true;
}
return $args;
}
Alternatively, if you've defined a custom taxonomy that you'd like to allow drag & drop sorting on, you'll want to pass in a tax_position
parameter to the $args
array inside of register_taxonomy. You can place this line directly after 'hierarchical'
.
'tax_position' => true,
On the front end of the site, anywhere get_terms() is used to query a set of taxonomy terms, they will be returned in the order of their position on the taxonomy list. No additional steps need to be taken on on your end.
Indeed, you can! You'll have to assign the 'tax_position'
parameter to the taxonomy. You can do this easily, using the following sample code snippet.
You'll notice in the code snippet, the taxonomy we are using is 'category' - but you can change this value to suit your needs.
As mentioned above, the taxonomies need to have the parameter 'tax_position' => true
assigned to it. If the taxonomy is missing this parameter the items won't actually be sortable. For an example of how to implement it, please see the following code snippet.
With the release of WordPress 4.4 came taxonomy meta data, which gets stored inside of the wp_termmeta
table in the database. Each taxonomy is assigned an integer value related to it's position on the taxonomy list.
yikes_simple_taxonomy_ordering_capabilities
- Filter to adjust who can access the 'Simple Taxonomy Ordering' settings page.yikes_simple_taxonomy_ordering_excluded_taxonomies
- Filter to add additional taxonomies or remove default taxonomies. Items in this array will not be displayed in the dropdown on the settings page, and thus cannot have drag and drop sorting enabled.
If you're running into any issues, we would love to hear about it. Please head over to the Simple Taxonomy Ordering Issue Tracker and create a new issue.
Now Maintained by Evan Herman in Lancaster, PA.