As far as I know, the way to create a taxonomy term is having to go into the taxonomy module and creating on there, and THEN assigning the term to the node.

Is there a way to create taxonomy terms on the fly? When the node is created, if the taxonomy term doesn't exist, it should be created too.

4 Answers 4


Use the Hierarchical Select module:

Hierarchical Select has the ability to save the entire lineage of a selection or only the "deepest" selection. You can configure it to force the user to make a selection as deep as possible in the tree, or allow the user to select an item anywhere in the tree. Levels can be labeled, you can configure limit the number of items that can be selected, configure a title for the dropbox, choose a site-wide animation delay, and so on. You can even create new items and levels through Hierarchical Select!

Another way is selecting Autocomplete term widget (tagging) as field widget, when creating your term reference field

As another option, there is the Simple hierarchical select module.

  • 1
    I always thought Autocomplete was solely for searching already created terms. Thanks for telling me about it. Commented Dec 29, 2011 at 16:41
 //see if this term already exists and fetch it if it does
  $term = taxonomy_get_term_by_name($i);

  //if it doesn't exist, make it
  if ($term == array()){
    //make a new class to hold the term for taxonomy 1
    $taxonomy = new stdClass();
    $taxonomy->name = $i;
    // mentioned vid here as of now i placed 1.
    $taxonomy->vid = 1;
    //now fetch it so we have it's tid
    $term = taxonomy_get_term_by_name($i);

  //set $tid as it's returned from  taxonomy_get_term_by_name
  $tid = key($term);

  //tag the node with the appropriate tag
   $node->field_tags['und'][0] = array('tid' => $tid);

  //save the tagged node

Above code will check for term exist and if not creates new term, when creating new content.

  • This little snippet of code has help me oh so many times, that I just want to say thank you for sharing it.
    – Emil Orol
    Commented Feb 2, 2016 at 21:30
  • Just to note here.. The the vid is not the version id as used for revisions, but its the Vocabulary ID. If you don't want to use the VID you can use $tazonomy->vocabulary_machine_name Commented May 10, 2016 at 1:58

In addition to the above suggestions, once can go for autocomplete_delux(https://www.drupal.org/project/autocomplete_deluxe) and entity_autocreate(https://www.drupal.org/project/entityreference_autocreate) modules.

These behave in manner just as the above modules; plus they fall under Drupal Security Policy


I'd like to suggest the Manage Multiple Terms module:

Manage Multiple Terms provides a simple mechanism to add, update, delete many terms in the same time easily and quickly.

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.