Wednesday, September 5, 2012

Get all the children from an taxonomy term



You have pass the tid into this function which will return all the child terms under it.
<?php
function taxonomy_get_children_all($tid, $vid = 0, $key = 'tid'){
  $c = taxonomy_get_children($tid, $vid, $key);
  $result = array();
  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;
}
?>

No comments:

Post a Comment