I have a custom taxonomy and for each parent there are one or more children, this is an example:
I need to query this taxonomy and get the children of a defined terms.
For example I need to get all the children of MI
and in this case should return just Milano
.
MI have the ID set to 31
so I used this query to get all the children:
$children = get_term_children(31, 'posizione_geografica');
where posizione_geografica
is my taxonomy slug.
If var_dump
the $children
I alway get 0
but, as you can see from the image, MI
has children.
How should I modify the query?
get_term_children()
will return an empty array if the term does not exist in WP. Are you sure31
is the ID ofMI
? What page are you trying this on? Can you useget_queried_object()
to return the term ID and populate theget_term_children()
function dynamically? – Ty Baileyget_terms
– Christian Giupponi