Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

Drupal 9 loop term objects to retrieve term data (id, name, uuid)

// Get an array of term objects for the given vocabulary
$terms = Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadByProperties(['vid' => 'my_vocabulary_machine_name']);


if (!empty($terms)) {

  foreach ($terms as $term) {
    //Only return comments that "published" status.
    if ($term->status->value == 1) {
      // These assignments show how to
      // get the term's id, name, and uuid.
      $terms_array[] = [
        'term_tid' => $term->id(),
        'term_name' => $term->name->value,
        'term_uuid' => $term->uuid->value,
      ];
    }
  }

}
 
PREVIOUS NEXT
Tagged: #Drupal #loop #term #objects #retrieve #term #data
ADD COMMENT
Topic
Name
7+7 =