Advanced Taxonomy Term Ordering
Article Last Updated: March 4, 2021
Do you want to order your taxonomy terms differently in multiple locations?
For example, let’s say you have a list of post categories ordered like so with Simple Taxonomy Ordering:
- Cook Books
This might be the order you want those terms to display, except for in one location. Let’s say you want them to be ordered by name in one location.
Here’s how you would reorder your taxonomy terms by name for one location in your theme, and then restore the custom order once you’re done.
remove_filter( 'terms_clauses', [ Yikes_Custom_Taxonomy_Order::get_instance(), 'set_tax_order' ], 10, 3 ); wp_list_categories( [ 'orderby' => 'name', 'order' => 'ASC', ] ); add_filter( 'terms_clauses', [ Yikes_Custom_Taxonomy_Order::get_instance(), 'set_tax_order' ], 10, 3 );
The code above would be placed in your theme where you want the alternately ordered taxonomy to display.
- Remove the filter which controls the custom taxonomy ordering.
- Next we’re using
wp_list_categoriesto order our categories by name.
- Finally, we’re restoring our filter and any of our calls to
wp_list_categorieswill be our custom order