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

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.

Smantha (not verified)

Unbelivable, that this capacity still has no parameter to channel the outcome by vid. Despite the fact that the they recommand to have the $options [url=https://www.courseworkcamp.co.uk/]Coursework Writing UK[/url] parameter deplored for the inward capacity, you can utilize this for the vid channel.
Rather than stacking and circling over the whole scientific categorization tree which could be possibly huge, it is smarter to utilize an Entity Field Query here looking for the term Foo in vocabulary .

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 VB.net platform?

Anonymous (not verified)

Thanks for teaching us how to do this in Drupal 8. I asked my mates who rush my papers me about how can I load taxonomy in Drupal 8, but they didn't give me an answer, and that made me really sad, you know. I am alright now.

Rahul Singh (not verified)

My brother suggested I might like this website. He was entirely right. This post actually made my day. You cannot imagine simply how much time I had spent for this info! Thanks! Filter Papers

Add new comment