You could use it like this
foreach (get_terms('industries') as $cat) :
echo( '<a href="' . get_term_link($cat->slug, 'industries') . '">' . $cat->name . '</a>' );
endforeach;
provided your terms are all ‘industries’ who have a different order.
You can read up about get_terms(), get_term_link() and related functions here:
HI @bph,
I think @jmlapam asked how to get terms in correct order when listing ONE POST’s terms. Function get_the_terms() has no arguments for this.
But! There is solution: don’t use get_the_terms( $post->ID, 'my_tax ), use
$sorted_terms = wp_get_object_terms( $post->ID, 'my_tax', array( 'orderby' => 'order' ) )
It works!
-
This reply was modified 9 years, 8 months ago by
mklusak.
Thank you. Great help! I need to learn more about wp_get_object functions really!
For those WordPress users a little less on the developer site:
I also used wp-term-order plugin by @johnjamesjacoby. It has a nice drag & drop interface for ordering and the get_terms() comes out in the custom order, too.
Oh God no, I was wrong! I too use WP-Term-Order, but as the get_the_terms() is unaffected, the wp_get_object_terms() is unaffected, too. It only listed terms in different order, that was coincidentally same as my custom order.
Well, that sucks.
Finally, there is a messy solution – I have to get all taxonomy terms (that are ordered by WP-Term-Order plugin). Then I have to get all post terms (unordered). And I extract those ordered terms that are connected to the post.
global $post;
$correctly_ordered_post_terms = array();
$used_terms = array();
$post_terms_unordered = get_the_terms( $post, 'my_taxonomy' );
// if( ! $post_terms_unordered ) return false; // post has no term
foreach( $post_terms_unordered as $post_term ) {
$used_terms[ $post_term->term_id ] = $post_term;
}
$all_taxonomy_terms_ordered = get_terms( 'my_taxonomy', array('orderby' => 'order') );
foreach( $all_taxonomy_terms_ordered as $ordered_term ) {
if( isset($used_terms[ $ordered_term->term_id ]) ) {
$correctly_ordered_post_terms[] = $used_terms[ $ordered_term->term_id ];
}
}
$correctly_ordered_post_terms // ... array with ordered post terms.