You can write a get_the_terms filter to change the other the category values are returned, e.g.
function sort_the_terms( $terms, $post_id, $taxonomy ) {
if ( 'categories' === $taxonomy ) {
usort( $terms, function( $term1, $term2 ) {
// Better sort logic here
return $term1->name <=> $term2->name;
} );
}
return $terms;
}
add_filter( 'get_the_terms', 'sort_the_terms', 20, 3 );
You’ll need to change the logic in the comparator to get the order you want, e.g. using information in wp_termmeta or the group or parent ID of the term. (If you’re using parents to build a hierarchy you might need something more complicated than just a usort though, since ‘place in hierarchy’ is going to be difficult to determine completely in a comparator.)
Related Posts:
- Order get_terms() By Custom Field
- How to Change the Categories Order in the Admin Dashboard?
- Sort posts by tags in category pages
- Display all posts in category, with specific tag posts at top
- I want to order categories based upon the latest post time
- WordPress Ordering Problem. How to fix ordering 1-10-100 issue?
- Order posts by category name
- Custom order categories in admin dashboard
- Arrange posts by date in front page
- How to redefine the sorting of product categories by menu_order?
- Order categories by name or view count
- WooCommerce – How to show specific category first-rest of products-specific category last
- Custom taxonomy/category order
- I want to display the all the posts that are inside a certain subcategory
- wp e-commerce group product by category [closed]
- List posts in alphabetical order
- Custom loop of a single category, cannot order by date. What am I missing?
- How do order product categories – on a parent category page – in Woocommerce?
- Natural sort / ordering wp_dropdown_categories
- Sort posts alphabetically by category/custom taxonomy, insert divider between different types
- How can I order all subcategories alphabetical independent of the parent categories?
- Ordering terms whilst in loop
- Modifying category order
- Configure query with multiple categories in a custom order?
- $args Orderby The number
- Woocommerce custom taxonomy order
- Woocommerce – Display product category of product in Orders page
- Post list category plugin alphabetical order [closed]
- Create a category list page
- How do I use the same post slug for different Categories?
- How to display only 3 main categories, separated by commas, since they are marked in the post?
- How to tax query X number of posts related by tag first, then by category if not enough in tag-related
- Woocommerce product categories order [closed]
- How do I create a way for users to assign categories to a post from the frontend?
- How to hide a specific category posts in my monthly archive?
- Give specific category its own permalink structure
- Create terms when registering taxonomy?
- Automated adding of one tag to all the posts in a category
- How to set up sub-categories for author pages?
- Add category to custom post type automatically, using category slug
- How do I edit pre_get_post for the category the user is currently in?
- Assign different category colours to different categories in the main menu
- wp_list_categories, Add class to all list items with children
- Display Only One Category
- Using separator with wp_list_categories
- Connecting WordPress gallery to custom categories (taxonomy)
- Multi-site or categories?
- Custom Category/Subcategory structure
- Remove ‘rel’ attributes from the_category() output
- Default category link for a custom category is a broken link
- View the latest created categories
- If statement within PHP echo
- category hierarchy level as a body class – parent cat =1, child cat=2, grandchild=3
- How to show author name only if the post is in a specific category?
- Are Category or Tag Archive Pages Possible?
- How to Exclude post from a category
- Hiding a Categories content on just the Homepage ‘Posts’?
- How to change a post category when the ACF datepicker Field is today
- Multiple Loops on category.php with pagination on last loop
- Two separate portfolio pages [closed]
- woocommerce related products by specific categories [closed]
- Child categories doesn’t echo if it doesn’t contain at least a post
- Display all product tags associated with a specific product category
- How replace individual elements in the RSS feed with a single string
- Category url generate 404 error
- Style a category from category list
- Adding a page summary to a specific page
- Adding a block with query in homepage
- Add a category on all archive category pages
- what file I need to create to work date archive links?
- multiple values in an array for category__and does not work with WP_Query
- Assigning certain pages or posts to use the template of the parent page or category
- I need advice on how to structure the categories according to the layout i have
- How to get posts using category slug in ClassiPress?
- Assign author to category and not only posts
- Add properties to term object
- How to fetch common posts from two feeds?
- Display all Categories
- How to set acf color field as background color to product category
- How to target all woocommerce categories that don’t have any subcategories in them?
- How to add all subcategories as submenu in WordPress menu
- echo $category[0]-> cat_name; shows only one category name
- Category pages resolving with and without category prefix
- Is there a way to allow users to customize their feed view?
- Number of categories slowing down the site
- Change post category within pre_get_posts
- Subcategory Page 404ing
- displaying one category on one page
- Ajax Category add doesn’t update the list table custom column
- Question About Messing With Category Pages and Descriptions
- how to get postmeta info based on multiple categories?
- create post with main category and other categories from admin panel
- How to exclude category and post_tag taxonomy while displaying custom taxonomy?
- List Terms by category
- Add advertising box to a specific category page
- How do you add Author and date Published on Category Pages?
- Twenty Eleven Theme [duplicate]
- display certain category on custom template page
- List products from current category
- How to show posts of a specific category