1

How can I get the last saved vid. taxonomy_vocabulary_save($vocabulary); is not returning the vid. I have used the following way.

$vocabulary = new stdClass();
$vocabulary->name = 'Currencies';
$vocabulary->machine_name = 'currencies';
taxonomy_vocabulary_save($vocabulary);
// get the vid of currency
$vocabulary = taxonomy_vocabulary_machine_name_load('currencies');
//save a variable for vid
variable_set('currencies_vid', $vocabulary->vid);   

Is there any better method?

1 Answer 1

2

The vocabulary object that you pass to taxonomy_vocabulary_save() will automatically be populated with the new vid, so you don't need to reload the vocabulary after you've saved it.

This code will work fine:

$vocabulary = new stdClass();
$vocabulary->name = 'Currencies';
$vocabulary->machine_name = 'currencies';
taxonomy_vocabulary_save($vocabulary);

variable_set('currencies_vid', $vocabulary->vid);   
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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