function global_filter_get_tid in Views Global Filter 7
Same name and namespace in other branches
- 8 global_filter.module \global_filter_get_tid()
Utility function to convert a term name to its associated taxonomy term id.
Parameters
string $term_name: e.g., 'Amsterdam'
string $vocabulary_machine_name: (optional) e.g., 'city' or simply omit, if known to be unique
Return value
int|string The term id if found, otherwise the term name that was passed in.
1 call to global_filter_get_tid()
File
- ./
global_filter.module, line 513 - global_filter.module
Code
function global_filter_get_tid($term_name, $vocabulary_machine_name = NULL) {
if (!module_exists('taxonomy')) {
drupal_set_message(t('Global Filter: you must enable the Taxonomy module in order to use function %name.', array(
'%name' => 'global_filter_get_tid()',
)), 'error');
return '';
}
foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) {
if (empty($vocabulary_machine_name) || $vocabulary_machine_name == $vocabulary->machine_name) {
foreach (taxonomy_get_tree($vid) as $term) {
if ($term_name == $term->name) {
return $term->tid;
}
}
}
}
return $term_name;
}