Intro To Taxonomy CSV (Part 2): Import Terms With Custom Fields

In part 1 of this series, we imported a list of terms as a flat and tree structure. We also became familiar with Taxonomy CSV‘s import and export page. We imported a simple list of terms in part 1. In Drupal 7, taxonomy terms have become a lot more powerful such as the ability to attach fields to terms.

In this tutorial, we’ll import terms that have a custom field.

Tags Vocabulary

Before we begin, let’s go and add a field to the Tags vocabulary. We’ll call this field Website and use the field to store a URL.

1. Go to Structure -> Taxonomy and click on the “edit vocabulary” link within the Tags row.

2. Click on the “Manage fields” tab in the top right corner.

Fig 1.0

3. Create a Website field using the settings defined in Table 1-0.

Table 1-0. Define a Website field

Option Value
Label Website
Machine name field_tags_website
Field type Text
Widget Text field

4. On the edit page, leave the “Text processing” selected as “Plain text”.

Fig 1.1

5. Scroll to the bottom and click on “Save settings”.

Create CSV File

Now what we’ll do is enter our terms into a spreadsheet in the right column order. Once we have entered all the terms, we’ll export the spreadsheet out as a CSV file and import that CSV into our site.

Open up a spreadsheet tool like Excel, Numbers or LibreOffice Calc and enter terms using the order of the columns below:

name, vocabulary_machine_name, description, format, weight, parent, field_tags_website

I’ll use LibreOffice Calc through out this tutorial.

1. Open LibreOffice Calc and enter a list of term names and website URLs. For this example, I created the following list:

Fig 1.2

2. In LibreOffice Calc go to File -> “Save As…” and select “Text CSV (.csv)” from the “File type” drop-down list.

Save the spreadsheet as a CSV file somewhere on your filesystem.

3. Open the saved CSV into a text editor and it should look something like this:


Import CSV File

In the last section, we created our CSV file, now let’s import this file into our website.

1. Go to Structure -> Taxonomy and click on the “CSV Import” (admin/structure/taxonomy/csv_import) tab in the top right corner.

2. In the first vertical tab (1. What do you want to import?), select the “Fields” radio button.

3. Taxonomy CSV needs to know the order of the columns in our CSV file. Copy the line of text below into the “Set order of items on a csv line” text field.

name, vocabulary_machine_name, description, format, weight, parent, field_tags_website

Fig 1.3

4. In the second vertical tab (2. Where are items to import?), select the “In a local file” radio button and choose the CSV that we just created.

Fig 1.4

5. Skip step three (3. How is your source formatted?).

6. In the fourth vertical tab (4. Which vocabulary do you want to import into?), you decide which vocabulary the terms will be imported into. Select the “Import in an existing vocabulary” radio button and Tags from the “Vocabulary choice” drop-down list.

Fig 1.5

Finally, check the “Automatically delete all terms of the selected vocabulary before import” checkbox. This will delete the existing terms and replace them with the imported ones.

Fig 1.6

7. You can ignore steps five and six. Scroll to the bottom and click on the Import button.

If everything imported properly, you should be able to see a URL in the website field.

Fig 1.7

Important: In Taxonomy CSV 7.x-5.10 (latest stable), you can NOT import a hierarchical tree structure with custom fields at the same time using a single CSV file. This functionality is available in the latest development release (7.x-5.x-dev).

If you have any questions, please leave a comment.

9 thoughts on “Intro To Taxonomy CSV (Part 2): Import Terms With Custom Fields”

  1. This article seems to me to be very interesting, and it is possible that it me is of great help. For my city there is generated a CSV file that changes every hour. It shows the temperature, rainfall, etc …. of last 24 hours. Is my question if I can obtain the information of the temperature in the last hour?…

    Example: ” temperature 11 º C “

  2. Thanks for the tutorial! I was wondering what I should do to use Taxonomy CSV Import to import custom fields where one of the fields is a checkbox type, i.e. can contain multiple values. Thank you!

  3. Hi Ivan
    Thanks for your tutos, are great!; I am trying to import a 45,000 items 5 levels deep taxonomy classification to my drupal site, my structure is parent_id_number, cat_id_number, and category name, how this can be done?
    notice that I have ID_NUMBERS instead of parent_name, child_name, sub-child_name, etc.

Leave a Comment

You have to agree to the comment policy.

This site uses Akismet to reduce spam. Learn how your comment data is processed.