Programatically create taxonomy terms

Writing code to bulk create taxonomy items without parent is really easy.

Function taxonomy_term_save($term) requires an object as parameter. An array containing the term name and the vocabulary where to insert is parsed as an object and added as argument. This example shows inserting data in its simplest form, only a name and a vocabulary id is needed.



// Mass save taxonomy items to a vocabulary.
$terms = array(
  'Dutch',
  'French',
  'German',
  'Chinese',
  'Russian',
  'English',
);

$vid = 1;

foreach ($terms as $term) {

  taxonomy_term_save((object) array( 
    'name' => $term,
    'vid' => $vid,
    )
  );

}