Hi,
I wrote a script to import an old database into a drupal install. Everything works fine exept saving those fields defined as "Content Taxonomy Fields" with "Autocomplete (freetagging)".
If I try to set up this fields as standard CCK type and save them through node_save api function this not works. I tried several array configuration but none of them works.

For example, a standard cck field is get saved correctly with

        (....)
        $nodetmp->field_data_nascita = array(array('value' => $corridore->field_data_nascita));
        (....)
        node_save($nodetmp);

Any idea about saving a field of this type with the node_save function?

Thanks a lot.

Comments

fitzkarraldo’s picture

Title: Using node_save with a Contenty Taxonomy Field » Using node_save with a Content Taxonomy Field
trevorbradley’s picture

I know this is an old post, but you need to save the taxonomy tid instead of the text field.

I had to write a function to pull data from the taxonomy tables, and I just managed to get this to work. Perhaps this could help someone else later on:

  function taxonomy_get_vocabulary($vid) {
    $db_result = db_query(db_rewrite_sql("SELECT t.tid, t.* FROM {term_data} t WHERE vid = %s", 't', 'tid'), $vid);
    $result = array();
    while ($term = db_fetch_object($db_result)) {
      $result[$term->name] = $term->tid;
    }
    return $result;
  } 

  $my_vocabulary = taxonomy_get_vocabulary(4); //or whatever your vocabulary vid is.

  $node->field_my_cck_content_taxonomy[]['value'] = $my_vocabulary["My Taxonomy Term"];

Hope this helps someone out!

magnus’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.