Wordpress- How to get term name from term_ID?
You may get the term name from term_id like this:
$term_name = get_term( $term_id )->name;
Explanation:get_term()
returns the term object and name
is one of propeties of this object.
More details on codex:https://codex.wordpress.org/Function_Reference/get_term
Please try this:
<?php $term = get_term_by( $field, $value, $taxonomy); ?>
Note:
- $field => Just write
'id'
here - $value => Place your
'term_id'
value here - $taxonomy => write your custom taxonomy
'slug'
here
For ex: My custom taxonomy slug
is 'services
' & 'term_id
' is 5
, so here is the code for retrieving 'term_name'
:
<?php $term = get_term_by( 'id', 5, 'services' ); echo $term->name; ?>
I hope, this may be helpful to you.