13

How would you programmatically create taxonomy term? I wish to bulk create some in a custom module.

11

You'll want to use taxonomy_save_term. The array you pass in to taxonomy_save_term should look like this.

$term = array(
 'name' => 'Taxonomy Term 1',
 'vid' => 1, // The VID of the vocabulary this term should be saved under
 'description' => 'A description of this term', // Not required
 'weight' => 5, // Not required
);
taxonomy_save_term($term);
  • 'weight' can also be included here – Shoaib Nawaz Jun 21 '11 at 12:55
  • 1
    There is also parent, relations, and synonyms but I didn't feel those were as important ;) – ericduran Jun 21 '11 at 13:10
  • 1
    @Shaoib: did you know that you can edit answers on stackexchange, and enhance the answer with your knowledge? I added the weight property and also finished up the code example with a taxonomy_save_term() call. – marcvangend Jun 21 '11 at 13:11
  • Term creation for Drupal 7 – Dimetry Jun 9 '16 at 6:16

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.