How to load taxonomy term by name in Drupal 8

Posted by admin on Fri, 01/19/2018 - 14:57

Code snippet to load taxonomy term by name (or any otehr property) in Drupal 8.

$term_name = 'Your Term Name';
$term = \Drupal::entityTypeManager()
      ->getStorage('taxonomy_term')
      ->loadByProperties(['name' => $term_name]);

If you want to use vid and name - just add that to properties array like this:

$term_name = 'Your Term Name';
$vid = 3;
$term = \Drupal::entityTypeManager()
      ->getStorage('taxonomy_term')
      ->loadByProperties(['name' => $term_name, 'vid' => $vid]);
×

Hey! Don't miss a new cool stuff!

Comments

Niharika Singh (not verified)

Very interesting, good job and thanks for sharing such a good blog. your article is so convincing that I never stop myself to say something about it. escorts in hyderabad

Tomoko (not verified)
Rosemary (not verified)
Alica (not verified)
Melvina (not verified)
Lino (not verified)
Charla (not verified)
Cruz (not verified)
Libby (not verified)
Pat (not verified)
Wiley (not verified)
Ferne (not verified)
Trent (not verified)
Evangeline (not verified)

I'm really impressed with your writing skills as well as

with the layout on your blog. Is this a paid theme or did you modify it

yourself? Anyway keep up the excellent quality writing, it is rare

to see a great blog like this one nowadays.

buy generic viagra online

Jorge (not verified)

If some one wishes to be updated with newest technologies after that he must be pay a quick visit this site and be up to

date everyday. viagra without a doctor prescription

Michell (not verified)

Keep this going please, great job! viagra tablets

Estela (not verified)
Veta (not verified)
Shela (not verified)
Charles (not verified)
Harley (not verified)

Add new comment