Custom Taxonomy Order

Custom Taxonomy Order

توسط

Custom Taxonomy Order is a plugin for WordPress which allows for the ordering of taxonomy terms.

It supports the following features:

  • Order (custom) terms through a simple drag-and-drop interface.
  • No custom coding needed. It uses standard WordPress filters.
  • It uses the available WordPress scripts and styles.
  • The plugin is lightweight, without any unnecessary scripts to load into the admin.
  • It falls in line gracefully with the look and feel of the WordPress interface.
  • It is located under the Tools > Term Order menu in the backend.
  • Translated or translatable.
  • Custom functions to order the taxonomies themselves.
  • There is no Pro version, everything works in the Free version.

Compatibility

This plugin is compatible with ClassicPress.

Contributions

This plugin is also available in Codeberg.

  1. Upload the plugin folder to the /wp-content/plugins/ directory
  2. Activate the plugin through the ‘Plugins’ menu in WordPress
  3. Order terms in the admin menu under Tools > Term Order
  4. Optionally set whether or not to have queries of the selected taxonomy be sorted by this order automatically.
  5. Optionally set 'orderby' => 'term_order', 'order' => 'ASC' to manually sort queries by this order.
  6. Enjoy!

Upgrade Notice

If you update from the original Custom Taxonomy Order please deactivate that first, then activate this plugin.

Removal of database changes

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

سوالات متداول

I sorted the terms in the WordPress backend, but I don’t see it changed in the frontend

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.

How do I sort the terms when using a custom query?

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’.

I use get_term_children but the terms do not get sorted

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.

I have a custom taxonomy that uses the Tag Cloud functionality, but it doesn’t sort like it should.

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;
}
?>

I’m using the_tags function, but it doesn’t sort as it should.

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.

I use WooCommerce Attributes and Categories.

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 Products Categories, you can change the order on Product > Categories.
There’s a three-line icon next to each category, you can hold it and drag the category up or down to change the order.

What capabilities are needed?

For sorting the terms you need the manage_categories capability.

Can I sort the taxonomies themselves?

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.

Can I hook into saving the term order on the dashboard page?

‘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');
?>

Can I hook into changing the term order on the frontend?

‘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);
?>

Can I hook into the settings for each taxonomy to change the sorting behaviour?

‘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' );
?>

I use the GET parameter ‘orderby’ to order posts, but then it is ignoring term order

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' );
?>

How can I add my own translation?

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.

×
نظری برای این آیتم موجود نیست.
0 0 رای ها
امتیازدهی
اشتراک در
اطلاع از
0 نظرات
قدیمی‌ترین
تازه‌ترین بیشترین رأی
هیچ نسخه‌ای برای این آیتم موجود نیست.
★★★★★
★★★★★
4.8 /5 (96 نظر)

قیمت:

رایگان

نگارش

آخرین انتشار

10 اردیبهشت 1405

آخرین بروزرسانی

4 ماه پیش

نصب های فعال

50,000+

نگارش وردپرس

وردپرس 4.1+

تست شده از نسخه

وردپرس 6.9.4

نگارش PHP

PHP 7.0+

نسخه ها

0 نسخه