How to get the grandfather of a term in taxonomy in Wordpress? Consider the following tree:
-Cidade
-Farmacias
-farmacia central
-farmacia São José
I want to get the name of the city of the central pharmacy, for example.
How to get the grandfather of a term in taxonomy in Wordpress? Consider the following tree:
-Cidade
-Farmacias
-farmacia central
-farmacia São José
I want to get the name of the city of the central pharmacy, for example.
You can do something that I picked up from a answer from the WordPress StackExchange itself:
// determine the topmost parent of a term
function get_term_top_most_parent($term_id, $taxonomy){
// começa do atual
$parent = get_term_by( 'id', $term_id, $taxonomy);
// subir a árvore até encontrar um termo com parent = '0'
while ($parent->parent != '0'){
$term_id = $parent->parent;
$parent = get_term_by( 'id', $term_id, $taxonomy);
}
return $parent;
}