Check your version

This tutorial covers a topic in Drupal 7 which may or may not be the version you're using. We're keeping this tutorial online as a courtesy to users of Drupal 7, but we consider it archived.

Last updated June 7, 2017

Check and create taxonomy terms programmatically.

Objectives and Prerequisites

You will need the following knowledge and skills. If you need a review, check out the Resources section at the bottom of this page.

  1. Create taxonomy terms programmatically.
  2. Associate taxonomy terms with a node programmatically.


Write conditional logic to meet the following requirements: - If a taxonomy term already exists, get the term ID. - If the taxonomy term does not exist, create it and return the term ID.

Populate the Genre field with the relevant terms from the data object you retrieved from The Movie DB API in the previous lesson.


  • Taxonomy terms can be created programmatically.
  • Terms are associated with nodes via a term ID.


Creative Commons License

Drupal Training Resources by Damian Robinson are licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Based on a work at