Skip to main content
Category:

Code snippet that can be used to get children of taxonomy term in Drupal 8.

$vid = 'my_vocab_machine_name';
$parent_tid = 87; // the parent term id
$depth = 1; // 1 to get only immediate children, NULL to load entire tree
$load_entities = FALSE; // True will return loaded entities rather than ids
$child_terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree($vid, $parent_tid, $depth, $load_entities);
 foreach ($child_terms as $child_term) {
              $terme_name = $child_term->name;
}

Riadh Rahmi

Senior Web Developer PHP/Drupal & Laravel

I am a senior web developer, I have experience in planning and developing large scale dynamic web solutions especially in Drupal & Laravel.

Web Posts

Search

Page Facebook