Try to map a string to an existing term, as for glossary use.
Provides a case-insensitive and trimmed mapping, to maximize the likelihood of a successful match.
$name: Name of the term to search for.
$vocabulary: (optional) Vocabulary machine name to limit the search. Defaults to NULL.
An array of matching term objects.
function taxonomy_term_load_multiple_by_name($name, $vocabulary = NULL) {
$values = array(
'name' => trim($name),
);
if (isset($vocabulary)) {
$vocabularies = taxonomy_vocabulary_get_names();
if (isset($vocabularies[$vocabulary])) {
$values['vid'] = $vocabulary;
}
else {
// Return an empty array when filtering by a non-existing vocabulary.
return array();
}
}
return entity_load_multiple_by_properties('taxonomy_term', $values);
}