This page is archived
We're keeping this page up as a courtesy to folks who may need to refer to old instructions. We don't plan to update this page.
Check and create taxonomy terms programmatically.
Goal
In a custom module, create taxonomy terms and relate them to a node.
Prerequisites
You will need the following knowledge and skills. If you need a review, check out the Additional resources section at the bottom of this page.
- Create taxonomy terms programmatically.
- Associate taxonomy terms with a node programmatically.
Tasks
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.
Recap
- Taxonomy terms can be created programmatically.
- Terms are associated with nodes via a term ID.
Further your understanding
- Continue to the next lesson: Movie Project: Import Data in a Site Update.
Additional resources
- API Documentation: Taxonomy functions (api.drupal.org)