Saturday, 31 August 2013

How can I show only one taxonomy from a post?

How can I show only one taxonomy from a post?

I have a custom post type and inside the custom post I have a taxonomy
named "instruments". Each post can have more than one "instrument".
But I just want to display one (or the first one) at the homepage. Like:
"Instrument A, Instrument B, Instrument C. But only show Instrument A".
Right now I'm using this code.
<?php
$terms = get_the_terms( $post->ID , 'instruments' );
foreach ( $terms as $term ) {
echo $term->name;
}
?>

No comments:

Post a Comment