Hi,
I'm trying to assign a term to an Image node when it is created. I look at an argument passed in the URL to work out which term to assign to the Image.
First I tried to add the term by assigning a value to $form['taxonomy'] in the image_form, and in the image_form_alter hooks.
I couldn't get that to work, so I tried doing this in the image_insert hook:
$result = db_query('INSERT INTO {term_node} (nid, tid) VALUES (%d, %d)', $node->nid, $term_tid);
This seems to be writing a value to the database ($result = 1) but if it does, the value is later deleted by some other process when the node is created.
I have checked, and $node->nid and $term_tid are both valid values.
The user makes a selection from two other sets of vocabulary terms when creating the image, and they are written to the database OK.
Any idea what might be going wrong here?
Thanks for help.
Comments
Your saving of a value to
Your saving of a value to the database is overwritten by the way taxonomy saves/updates values. You could write a small module that implements hook_nodeapi and for the case where $op equals 'submit' check the node type and if it is the one you want do
I will try that - thanks. I
I will try that - thanks.
I wonder if that is also the issue when I'm trying to add the term in the form hooks?
I was trying to do something like:
form['taxonomy'][$vid] = array($tid=>$tid);
When it didn't work I presumed I just had the syntax wrong...
I think
I think
$form['taxonomy'][$vid] = array($tid=>$tid);>should besince it needs to be a from element.
Yes that worked! Many thanks
Yes that worked!
Many thanks :)