1.20.x taxonomy.module | taxonomy_term_load_children($tid, $vocabulary_name = NULL) |
Finds all children of a term ID.
Parameters
$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.
File
- modules/
taxonomy/ taxonomy.module, line 1006 - Enables the organization of content into categories.
Code
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);
}
$query->addTag('taxonomy_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();
}