I have a custom taxonomy filled with terms such as ‘volume 1’, ‘volume 2’, ‘issue 1’, ‘issue 2’, ‘issue 10’ and get_terms orderby name returns list as:
issue 1, issue 10, issue 2 though I need it to be issue 1, issue 2, issue 10
I tried searching wp.stackexchange and using my google-fu to no avail. Any help would be greatly appreciated.
4 Answers
I know this post is very old but still answering for others who reach here.
Following is a very simple filter to sort the terms as numbers. You only need to set the variable $taxonomy_to_sort
with taxonomy slug
and place it in functions.php
of your theme.
add_filter( 'get_terms_orderby', 'terms_order_as_number', 10, 3);
function terms_order_as_number($order_by, $args, $taxonomies){
$taxonomy_to_sort = "numbers";
if(in_array($taxonomy_to_sort, $taxonomies)){
$order_by .= " * 1";
}
return $order_by;
}