Drupal 6 importing taxonomy terms easy mode

Posted by: 
Dominique De Cooman

I just discovered a very handy api to import taxonomy.
It is included with the taxonomy csv module in the file taxonomy_csv.api.inc

I needed to do something very simple import some terms into a vocabulary (no hierarchy, no related terms, just tags..). I already had my csv parser to create my nodes so I did not use the interface of the module. Since I had my terms in an array I just needed to prepare them and import them with this api function :

$terms = array(
'name' => $data[20]),
'name' => $data[21]),
'name' => $data[22]),
'name' => $data[23]),
'name' => $data[24]),
'name' => $data[27]),
'name' => $data[28]),

  foreach (
$terms as $term) {
//voc id
$term['vid'] = ASSOC;
    if (
$term['name']) {
//this is the function

But this is not it, the modules api can do a lot more. Import vocabularies in total, create hierarchies, related terms, ...
All help is in the files comments.

Add new comment

Who are you?

By knowing who you are you will be directed to a page where we have displayed all our drupal services relevant to your professional identity.