Skip to content

Instantly share code, notes, and snippets.

@craychee
Last active August 29, 2015 13:59
Show Gist options
  • Select an option

  • Save craychee/10745141 to your computer and use it in GitHub Desktop.

Select an option

Save craychee/10745141 to your computer and use it in GitHub Desktop.
A script that creates the terms for a vocabulary.
<?php
/**
* * Create a taxonomy term and return the tid.
* */
$cat_terms = array(
'Backup & Sharing' => array(),
'Computer Security' => array(),
'Equipment Protection' => array(),
'ID Protection' => array(),
'Technical Support' => array(),
);
$category = taxonomy_vocabulary_machine_name_load('category');
$category_vid = $category->vid;
foreach($cat_terms as $key => $value) {
create_taxonomy_term($key, $category_vid);
}
$customer_terms = array(
'Personal Product' => array(),
'Small Business' => array(),
);
$customer = taxonomy_vocabulary_machine_name_load('customer_type');
$customer_type_vid = $customer->vid;
foreach($customer_terms as $key => $value) {
create_taxonomy_term($key, $customer_type_vid);
}
function create_taxonomy_term($name, $vid) {
$term = new stdClass();
$term->name = $name;
$term->vid = $vid;
taxonomy_term_save($term);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment