1 taxonomy.module taxonomy_term_load_children($tid, $vocabulary_name = NULL)

Finds all children of a term ID.


$tid: A taxonomy term ID.

$vocabulary_name: An optional vocabulary name to restrict the child search.

Return value

An array of term objects that are the children of the term $tid, or an: empty array when no children exist.


core/modules/taxonomy/taxonomy.module, line 944
Enables the organization of content into categories.


function taxonomy_term_load_children($tid, $vocabulary_name = NULL) {
  $children = &backdrop_static(__FUNCTION__, array());

  if ($tid && !isset($children[$tid])) {
    $query = db_select('taxonomy_term_data', 't');
    $query->join('taxonomy_term_hierarchy', 'h', 'h.tid = t.tid');
    $query->addField('t', 'tid');
    $query->condition('h.parent', $tid);
    if ($vocabulary_name) {
      $query->condition('t.vocabulary', $vocabulary_name);
    $tids = $query->execute()->fetchCol();
    $children[$tid] = taxonomy_term_load_multiple($tids);

  return isset($children[$tid]) ? $children[$tid] : array();