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()
      ->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()
      ->loadByProperties(['name' => $term_name, 'vid' => $vid]);

Hey! Don't miss a new cool stuff!


Anonymous (not verified)

Not to be rude but I seriuosly don't understand the sense behind this post. You could've taken some help from AustralianWritings for better understanding. I am sure I am not the first person complaining about this.

Taylor Wilson (not verified)

Hi I am from Custom Essay Writing company and I have to ask a question that is what is Drupal in programming lots of programmer talk about Drupal is it kind of language or like platform?

Add new comment