We are using the following code to fetch all the taxonomy term values in the term_category vocabulary.
$db = \Drupal\Core\Database\Database::getConnection(); $term_categories = $db->query('select tid, vid from taxonomy_term_data where vid ='\'term_category\''); foreach($term_categories as $category) { $category_term = (\Drupal\taxonomy\Entity\Term::load($category->tid)); ksm($category_term->label()); // returns NULL. ksm($category_term->getName()); // returns NULL. } When we run it, we get NULL as label.
The Article content type has a field_category field that is an entity reference for the term_category vocabulary. Currently, no Article node has any value populated for that field, as it is optional.
Why I cannot get the taxonomy term name from its ID?
label()is more generic. Forget aboutgetName(). See Deprecate Node::getTitle() & other entity-type-specific calls in favour of Entity::label() for details.