Reply to comment

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 :

<?php
  
//prepare
  
$terms = array(
    array(
'name' => $data[20]),
    array(
'name' => $data[21]),
    array(
'name' => $data[22]),
    array(
'name' => $data[23]),
    array(
'name' => $data[24]),
    array(
'name' => $data[27]),
    array(
'name' => $data[28]),
  );

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

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.

Reply

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd><img><p><b><i><table><th><tr><td><blockquote><br /><img /><tbody><span><strike>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <codes>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. The supported tag styles are: <foo>, [foo].
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.