Last active
March 3, 2017 02:53
-
-
Save brooke-heaton/9c4ce984e5638e96b41a8ba6a03410ab to your computer and use it in GitHub Desktop.
Check if a Taxonomy Term exists by Term Name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This helper Drupal 7 function can look up if a term exists and is useful | |
* if adding terms in a postImport() method on a migration or | |
* if needing to avoid duplicates or relate entities to the term. | |
*/ | |
public function checkTermExistsByName($name) { | |
$query = new EntityFieldQuery(); | |
$entities = $query->entityCondition('entity_type', 'taxonomy_term') | |
->propertyCondition('name', $name) | |
->range(0, 1) | |
->execute(); | |
return $entities; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment