4

Here is the scenario.

I have a taxonomy term reference field, which is referenced to a taxonomy vocabulary, for example it is associated with category vocabulary. Now I need to fetch the vid of the category vocabulary which is associated to that particular field.

or is there a way to fetch the field settings in drupal 7?

  • you have tid and want to get vid – Ahmed May 15 '12 at 11:07
  • nope. thats not the case. – Mathankumar May 15 '12 at 11:19
  • you have node that contains a taxonomy ref. and you need to get vid – Ahmed May 15 '12 at 11:22
12

You can use a combination of field API and taxonomy API functions to get this info:

$field_name = 'field_FIELD_NAME';

// Get the field info
$info = field_info_field($field_name);

// The link to the vocab is stored as it's machine name
$vocab_machine_name = $info['settings']['allowed_values'][0]['vocabulary'];

// Load the vocab by machine name
$vocab = taxonomy_vocabulary_machine_name_load($vocab_machine_name);

// Finally, get the vid
$vid = $vocab->vid;
| improve this answer | |
  • 1
    its really awesome. Clive rock!!! – Mathankumar May 15 '12 at 11:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.