Access one term:
$term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->load(TID);
$value = $term->FIELD_MACHINENAME->value;
Example : load title and language of term id =2
$term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->load(2);
$title = $term->name->value;
langcode = $term->langcode->value;
And for load Multiple
$terms = $entityManager->getStorage('taxonomy_term')->loadMultiple($terms);
foreach ($terms as $term) {
var_dump($term->tid->value); //return tid of term
var_dump($term->name->value); //return title of term
}
No comments:
Post a Comment