function taxonomy_get_term_by_name in Drupal 7
Same name and namespace in other branches
- 4 modules/taxonomy.module \taxonomy_get_term_by_name()
- 5 modules/taxonomy/taxonomy.module \taxonomy_get_term_by_name()
- 6 modules/taxonomy/taxonomy.module \taxonomy_get_term_by_name()
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.
Parameters
$name: Name of the term to search for.
$vocabulary: (optional) Vocabulary machine name to limit the search. Defaults to NULL.
Return value
An array of matching term objects.
5 calls to taxonomy_get_term_by_name()
- TaxonomyHooksTestCase::testTaxonomyTermHooks in modules/
taxonomy/ taxonomy.test - Test that hooks are run correctly on creating, editing, viewing, and deleting a term.
- TaxonomyTermTestCase::testNodeTermCreationAndDeletion in modules/
taxonomy/ taxonomy.test - Test term creation with a free-tagging vocabulary from the node form.
- TaxonomyTermTestCase::testTaxonomyGetTermByName in modules/
taxonomy/ taxonomy.test - Test taxonomy_get_term_by_name().
- TaxonomyTermTestCase::testTermInterface in modules/
taxonomy/ taxonomy.test - Save, edit and delete a term using the user interface.
- TaxonomyTermTestCase::testTermMultipleParentsInterface in modules/
taxonomy/ taxonomy.test - Test saving a term with multiple parents through the UI.
File
- modules/
taxonomy/ taxonomy.module, line 1228 - Enables the organization of content into categories.
Code
function taxonomy_get_term_by_name($name, $vocabulary = NULL) {
$conditions = array(
'name' => trim($name),
);
if (isset($vocabulary)) {
$vocabularies = taxonomy_vocabulary_get_names();
if (isset($vocabularies[$vocabulary])) {
$conditions['vid'] = $vocabularies[$vocabulary]->vid;
}
else {
// Return an empty array when filtering by a non-existing vocabulary.
return array();
}
}
return taxonomy_term_load_multiple(array(), $conditions);
}