Skip to content

Instantly share code, notes, and snippets.

@matiskay
Created December 15, 2011 17:58
Show Gist options
  • Save matiskay/1482098 to your computer and use it in GitHub Desktop.
Save matiskay/1482098 to your computer and use it in GitHub Desktop.
Get Vocabulary by name
<?php
/**
* This function will return a vocabulary object which matches the
* given name. Will return null if no such vocabulary exists.
*
* @param String $vocabulary_name
* This is the name of the section which is required
* @return Object
* This is the vocabulary object with the name
* or null if no such vocabulary exists
*/
function mymodule_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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment