7.x taxonomy.module taxonomy_vocabulary_machine_name_load($name)

Return the vocabulary object matching a vocabulary machine name.

Parameters

$name: The vocabulary's machine name.

Return value

The vocabulary object with all of its metadata, if exists, FALSE otherwise. Results are statically cached.

See also

taxonomy_vocabulary_load()

1 string reference to 'taxonomy_vocabulary_machine_name_load'
taxonomy_form_vocabulary in modules/taxonomy/taxonomy.admin.inc
Form builder for the vocabulary editing form.

File

modules/taxonomy/taxonomy.module, line 1381
Enables the organization of content into categories.

Code

function taxonomy_vocabulary_machine_name_load($name) {
  $vocabularies = taxonomy_vocabulary_load_multiple(NULL, array(
    'machine_name' => $name,
  ));
  return reset($vocabularies);
}

Comments

Nick.D’s picture

stdClass Object
(
    [vid] => 1
    [name] => Tags
    [machine_name] => tags
    [description] => Use tags to group articles on similar topics into categories.
    [hierarchy] => 0
    [module] => taxonomy
    [weight] => 0
    [rdf_mapping] => Array
        (
            [rdftype] => Array
                (
                    [0] => skos:ConceptScheme
                )
            [name] => Array
                (
                    [predicates] => Array
                        (
                            [0] => dc:title
                        )
                )
            [description] => Array
                (
                    [predicates] => Array
                        (
                            [0] => rdfs:comment
                        )
                )
        )
)
zuernBernhard’s picture

To use this in Drupal 6 you can put this function somewhere in a custom module:

function get_vocabulary_by_name($vocabulary_name) {
  $vocabs = taxonomy_get_vocabularies(NULL);
  foreach ($vocabs as $vocab_object) {
    if ($vocab_object->name == $vocabulary_name) {
      return $vocab_object;
    }
  }
  return NULL;
}