0

I have a custom taxonomy (location) that is being populated automatically by an advanced custom field on user save. The issue is that it saves the term_id in the postmeta meta_value field. When I echo that field in my archive or taxonomy template it obviously shows me the term_id and not the actual term name (ex. I get 41, instead of California displaying). I have tried multiple things to get this to appear and days and basically any query I do ends up just a blank space displaying on my archive/taxonomy page. Can anyone assist me in how I might retrieve the term name from the term_id being outputted?

Thanks in advance!

1

You can use get_term_by to retrieve a term by its ID:

$term_id = 123;
$term = get_term_by( 'id', $term_id, 'location' );
if( $term ){
    echo $term->name;
}
  • Thank you. I just had to change the $term_id statement to make it variable $queried_object = get_queried_object(); $term_id = $queried_object->term_id; – Deon May 8 '13 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.