rdurbin
rdurbin

Reputation: 11

Drupal 6 - I am using drupal_execute to insert a CCK node into my site. Everything is working except taxonomy

  $form_state['values']['field_prx_mp3_labels'][0][value] = $mp3_labels;  
  $form_state['values']['taxonomy'][0][value] = array('tags'=>array('1'=>'Music'));  
  $errs = drupal_execute('prx_content_node_form', $form_state, (object) $nodeTmp);  

This is a Drupal 6 site. I am using drupal_execute to create a node programatically. The first line is working for field_prx_mp3_labels. The second (for taxonomy) is not.

Here is what my select on the node add for my cck looks like:

<select name="taxonomy[2][]" multiple="multiple"  class="form-select" id="edit-taxonomy-2"  size="9"><option value="">- None -</option><option value="5">Music</option><option value="6">-Rock/Pop</option><option value="7">-Jazz/Blues</option><option value="8">-Classical</option><option value="9">-Music Documentaries</option><option value="10">-Festivals/Concerts</option><option value="11">Arts</option><option value="19">-Literature</option><option value="12">Nature</option><option value="13">History</option><option value="15">-Music</option><option value="14">Culture</option><option value="17">-American Indian</option><option value="18">-Latino</option><option value="16">-Youth Perspective</option></select> 

I have tried many many variations for line 2 (relating to the taxonomy).

This comment seemed close but it hasn't worked for me: http://drupal.org/node/178506#comment-1155576

Thanks!

Upvotes: 1

Views: 643

Answers (2)

rdurbin
rdurbin

Reputation: 11

I ended up doing it a different way. Basically I run drupal_execute to push the CCK content in Drupal. Right after that runs I query the DB to get the ID of the node I just inserted. I then take that ID and run a loop that inserts the taxonomy relationships directly into the term_node table.

The possible problem this causes is the taxonomy information isn't available during the drupal_execute. That means if you are relying on the taxonomy for part of your pathauto/alias rules the taxonomy won't yet be available.

Upvotes: 0

Kevin
Kevin

Reputation: 13226

Doesn't [value] have to be in quotes?

And did you try this:

$form_state['values']['taxonomy'] = array('tags'=>array('1'=>'Music'));

Upvotes: 1

Related Questions