function taxonomy_get_children
7.x taxonomy.module | taxonomy_get_children($tid, $vid = 0) |
6.x taxonomy.module | taxonomy_get_children($tid, $vid = 0, $key = 'tid') |
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_get_children()
- TaxonomyTermTestCase::testTaxonomyTermHierarchy in drupal-7.x/
modules/ taxonomy/ taxonomy.test - Test terms in a single and multiple hierarchy.
- taxonomy_term_delete in drupal-7.x/
modules/ taxonomy/ taxonomy.module - Delete a term.
1 string reference to 'taxonomy_get_children'
- taxonomy_terms_static_reset in drupal-7.x/
modules/ taxonomy/ taxonomy.module - Clear all static cache variables for terms.
File
- drupal-7.x/
modules/ taxonomy/ taxonomy.module, line 1062 - Enables the organization of content into categories.
Code
function taxonomy_get_children($tid, $vid = 0) {
$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();
}