function taxonomy_term_load_children

Finds all children of a term ID.

Parameters

$tid: A taxonomy term ID.

$vid: An optional vocabulary ID 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.

2 calls to taxonomy_term_load_children()
TermStorageController::postDelete in drupal/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php
Overrides Drupal\Core\Entity\DatabaseStorageController::postDelete().
TermTest::testTaxonomyTermHierarchy in drupal/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php
Test terms in a single and multiple hierarchy.
1 string reference to 'taxonomy_term_load_children'

File

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

Code

function taxonomy_term_load_children($tid, $vid = NULL) {
  $children =& drupal_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 ($vid) {
      $query
        ->condition('t.vid', $vid);
    }
    $query
      ->addTag('term_access');
    $query
      ->orderBy('t.weight');
    $query
      ->orderBy('t.name');
    $tids = $query
      ->execute()
      ->fetchCol();
    $children[$tid] = taxonomy_term_load_multiple($tids);
  }
  return isset($children[$tid]) ? $children[$tid] : array();
}