Allows for the ordering of categories and custom taxonomy terms through a simple drag-and-drop interface
Custom Taxonomy Order is a plugin for WordPress which allows for the ordering of taxonomy terms.
It supports the following features:
This plugin is compatible with ClassicPress.
This plugin is also available in Codeberg.
/wp-content/plugins/
directory'orderby' => 'term_order', 'order' => 'ASC'
to manually sort queries by this order.If you update from the original Custom Taxonomy Order please deactivate that first, then activate this plugin.
First you can disable the plugin. Then in wp_options you can delete the field:
* customtaxorder_settings
* customtaxorder_taxonomies
In wp_terms you can remove the column
* term_order
Did you set the option for that taxonomy to use that custom order? Make sure to check it so the filters run
with your taxonomy.
When you use default functions like get_terms or get_categories, this should not be needed.
If you do need to, you can apply the sorting for the taxonomy by using:
‘orderby’ => ‘term_order’.
This function only fetches the ID’s of the terms, so it is impossible to sort them by term_order. If you do need the sort_order, use a function like get_terms with the ‘child_of’ parameter. That will fetch an array of WP_Term objects that can be sorted.
If it is a much used plugin, can you tell me what is the name for the taxonomy?
In the customtaxorder_wp_get_object_terms_order_filter it needs to be added, and the get_terms filter should not run
on that taxonomy. The tag_cloud_sort filter should do that.
If it is a custom taxonomy, you can also use a filter:
<?php add_filter( 'customtaxorder_exclude_taxonomies', 'add_taxonomy_to_customtaxorder_exclude_taxonomies' ); function add_taxonomy_to_customtaxorder_exclude_taxonomies( $taxonomies ) { $taxonomies[] = 'directory'; // name of your tag taxonomy. return $taxonomies; } ?>
There is a bug with the the_tags function, where it will sort according to the setting for categories.
This happens in the ‘customtaxorder_apply_order_filter’ function where the $args has two taxonomies but only one orderby can be returned.
This plugin only supports sorting the attributes/terms. These are the items like S, M and L.
For sorting the taxonomies like ‘size’, you need to sort them on Woo’s attributes page.
For sorting the terms you need the manage_categories capability.
There is an admin page to sort them, and save them in the database.
You can use a function to sort taxonomies themselves like this:
<?php $taxonomy_objects = get_object_taxonomies( 'post', 'objects' ); $taxonomy_objects = customtaxorder_sort_taxonomies($taxonomy_objects); foreach ( $taxonomy_objects as $tax ) { echo $tax->name . "<br />"; } ?>
The function requires a parameter with an array of taxonomy objects.
‘customtaxorder_update_order’ is being run when saving the order of terms in the admin page.
You could add the following example to your functions.php and work from there.
<?php function my_customtaxorder_update_order( $new_order ) { print_r( $new_order ); } add_action('customtaxorder_update_order', 'my_customtaxorder_update_order'); ?>
‘customtaxorder_terms_ordered’ action is being run after term array has been ordered with usort.
Please be aware that this can be triggered multiple times during a request.
You could add the following example to your functions.php and work from there.
<?php function custom_action( $terms_new_order, $terms_old_order ) { print_r( $terms_new_order ); } add_action('customtaxorder_terms_ordered', 'custom_action', 10, 2); ?>
‘customtaxorder_settings’ filter is being after fetching the settings for all taxonomies.
You could add the following example to your functions.php and work from there.
<?php /* * Example code to change the product_cat settings in WooCommerce on the main shop page. * * Settings: * 0: orderby Term ID * 1: orderby Custom Order * 2: orderby Term Name (alphabetical) * 3: orderby Term Slug (alphabetical) * 4: orderby Post Count (based on term_taxonomy table) * * Taken from: * https://wordpress.org/support/topic/product-categories-sort-how-to-sort-just-the-sub-terms-sub-categories/ * */ function my_customtaxorder_settings( $settings ) { //var_dump( $settings['product_cat'] ); if ( function_exists( 'is_shop' ) ) { if ( is_shop() ) { $settings['product_cat'] = 1; } } //var_dump( $settings['product_cat'] ); return $settings; } add_filter( 'customtaxorder_settings', 'my_customtaxorder_settings' ); ?>
In case the GET parameter ‘orderby’ is set it will be used to order terms, instead of posts, users, or anything else.
Therefore when that GET parameter is set, there is no custom order applied in this plugin.
You can add a filter to possible ignore the orderby parameter in the GET request.
That might be useful if your GET parameter for orderby is used to sort posts, users, or just anything that is not terms.
Example code for using the filter:
<?php function my_customtaxorder_is_get_orderby_set( $get_orderby_set ) { return false; // ignore orderby GET parameter // return $get_orderby_set; // this would be default behaviour } add_filter( 'customtaxorder_is_get_orderby_set', 'my_customtaxorder_is_get_orderby_set' ); ?>
Translations can be added very easily through GlotPress.
You can start translating strings there for your locale. They need to be validated though, so if there’s no validator yet,
and you want to apply for being validator, please post it on the support forum. I will make a request on make/polyglots to
have you added as validator for this plugin/locale.
term_relationships
table.