I have a custom order of my taxonomies in Woocommerce/Taxonomy Order.
When I display them, they get printed in alphabetical order.
How can I prevent this behavior and print them in the order I selected?
Thanks in advance!
I have a custom order of my taxonomies in Woocommerce/Taxonomy Order.
When I display them, they get printed in alphabetical order.
How can I prevent this behavior and print them in the order I selected?
Thanks in advance!
Share Improve this question asked Nov 23, 2016 at 11:35 Arno NymoArno Nymo 1 1- are you using any plugin or you did it manually using coding ? – GKS Commented Nov 23, 2016 at 11:41
1 Answer
Reset to default 0You may consider using the get_terms() function to generate a list of the items in a custom taxonomy. I'm sure there are other good ways of doing this, but there are plenty of parameters here you can try out to get the order you need.
$terms = get_terms( 'custom_taxonomy_here', 'orderby=count&hide_empty=0' );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
echo '<ul>';
foreach ( $terms as $term ) {
echo '<li>' . $term->name . '</li>';
}
echo '</ul>';
}
In the example above, orderby
orders the terms by their count (but there are other arguments for a different order) and hide_empty
to display terms whether or not they are associated with a post.