How to fix Error: Call to undefined method Drupal\taxonomy\Entity\Term::getVocabularyId()

 Since Drupal 9 you can get this error:

Error: Call to undefined method Drupal\taxonomy\Entity\Term::getVocabularyId()

Here is the solution: (remove the line with - and change with + line) 

-    $vocabulary = Vocabulary::load($term->getVocabularyId());
+    $vocabulary = Vocabulary::load($term->bundle());

 

 

Saved you some valuable time?

Buy me a drink 🍺 to keep me motivated to create free content like this!