I'm trying to list just the first taxonomy term outside the loop.
This is working fine but it lists all terms, and I just need the first - any suggestions?
$taxonomy = 'taxonomy-name-here';
$queried_term = get_query_var($taxonomy);
$terms = get_terms($taxonomy, 'slug='.$queried_term);
if ($terms) {
foreach($terms as $term) {
echo ' ' . $term->name . ' ';
}
}
Edit: clarification: the above seems to be returning all categories within the taxonomy, I'm only looking to get the taxonomy category of the current page.
Update: I found a simple answer!:
$categories= wp_get_object_terms($post->ID, 'taxonomy-name');
echo $categories[0]->name;
get_query_var($taxonomy);
is empty.