function taxonomy_term_load_multiple_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.

6 calls to taxonomy_term_load_multiple_by_name()
HooksTest::testTaxonomyTermHooks in drupal/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/HooksTest.php
Test hooks on CRUD of terms.
TermLanguageTest::testTermLanguage in drupal/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermLanguageTest.php
TermTest::testNodeTermCreationAndDeletion in drupal/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php
Test term creation with a free-tagging vocabulary from the node form.
TermTest::testTaxonomyGetTermByName in drupal/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php
Test taxonomy_term_load_multiple_by_name().
TermTest::testTermInterface in drupal/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php
Save, edit and delete a term using the user interface.

... See full list

File

drupal/core/modules/taxonomy/taxonomy.module, line 864
Enables the organization of content into categories.

Code

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'] = $vocabularies[$vocabulary]->vid;
    }
    else {

      // Return an empty array when filtering by a non-existing vocabulary.
      return array();
    }
  }
  return entity_load_multiple_by_properties('taxonomy_term', $values);
}