I found a very good example on retrieving the Vocabulary object by name.
/**
* 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 _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;
}
Example
$vocab_object = _get_vocabulary_by_name("<vocabulary name>");
$vocab_id = $vocab_object->vid;
Done =)
Reference: StackOverflow – get vocabulary id by name
