Wordpress get taxonomy name by term id
Asked Answered
S

3

11

Is there a way to pull taxonomy name just by using term id? Like i have a term_id and i don't know which taxonomy it belongs to and need to get the taxonomy name that it belongs too. any way?

Thanks!

Swale answered 21/3, 2017 at 16:29 Comment(0)
C
22

You can use get_term(): https://codex.wordpress.org/Function_Reference/get_term

$term = get_term( $term_id );
echo $term->taxonomy;
Caporal answered 21/3, 2017 at 17:9 Comment(2)
Note that this will return a "Invalid taxonomy" error if the taxonomy is not registered as "public".Nicias
If you are looking for the display name use $term->nameStreamlined
G
2

to get the labels of a taxonomy by one of its term ids, you would need to first get the term by calling

$term = get_term($term_id);

now you have the term object and that also includes $term->taxonomy. with that info you can call for the whole taxonomy

$taxonomy = get_taxonomy($term->taxonomy);

now you have the whole package and you could extract the name from that.

var_dump($taxonomy);

$label = $taxonomy->label;
$name = $taxonomy->labels->name;
$singular_name = $taxonomy->labels->singular_name;

or you could call another function, that gets you all the labels:

$labels = get_taxonomy_labels($taxonomy);

var_dump($labels);
echo $labels->name;
Geisler answered 28/7, 2023 at 9:26 Comment(0)
B
0

One can get taxanomy name using term id:

In the below example group_types is the custom taxonomy in WordPress

$groupTypeName = get_term_by('term_taxonomy_id','group_types' , 'category');
$tax_name= $groupTypeName->name;
echo $tax_name;
Bentz answered 2/3, 2023 at 12:30 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.