Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By bruceclothier on
Not sure where to put this but I need this quite often so wrote a simple function that someone else might find helpful.
function taxonomy_get_children_all($tid, $vid = 0, $key = 'tid'){
$c = taxonomy_get_children($tid, $vid, $key);
foreach ($c as $t => $d){
$result[$t] = $d;
$below = taxonomy_get_children_all($t, $vid, $key);
if (!empty($below)) {
foreach ($below as $nt => $nd){
$result[$nt] = $nd;
}
}
}
return $result;
}
Hope it's useful to someone.
Comments
Very Helpful
This was very helpful indeed! Thank you.
thanks alot
it helped me as well.
It helped me to but with one modification
For a corect output after:
put this line:
the function should look like this now:
Thanks for this func!
--
Works at Magazinul Cu Scule .ro
Make it hierarchical by children
New here
I know it's an old post, but please can someone tell me where to put this function? Thanks
_
It needs to go in a custom module.
Get child tids
Simple function to get all child tids.
________________________
Override, don't change!
How about
deleted
Please check this link https:
Please check this link https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/f...
To get all descendants of a particular term
I think that is the way to go, you'll get all the children and children's children. Check out the function and note that there is a max_depth that can be set.