Skip to content

Instantly share code, notes, and snippets.

@dmclark
Last active August 29, 2015 14:09
Show Gist options
  • Save dmclark/f118bad9c3a72a8eafc2 to your computer and use it in GitHub Desktop.
Save dmclark/f118bad9c3a72a8eafc2 to your computer and use it in GitHub Desktop.
function mit_gb_id_for_term($term_name,$vid)
{
$ret = NULL;
$query = new EntityFieldQuery;
$result = $query
->entityCondition('entity_type', 'taxonomy_term')
->propertyCondition('name', $term_name)
->propertyCondition('vid', $vid)
->execute();
// die(print_r(array_keys($result['taxonomy_term'])));
if ($result) {
$ids = array_keys($result['taxonomy_term']);
$ret = $ids[0];
} else {
$term = new STDClass();
$term->name = $term_name;
$term->vid = $vid;
$saved_term = taxonomy_term_save($term);
$ret = $saved_term->id;
}
return $ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment