views:

28

answers:

0

Hi everyone. I'm writing an action for Drupal 6.x that gets triggered every time a node is created or updated. In it, I need to add a (pre-existing) taxonomy term (of which I have the tid and vid) to the node that's just been created/edited. I've tried several approaches, none of which seem to work. I know I could, in principle, modify the term_node database table directly, but I was hoping there would be a Drupal-sanctioned way to do this. So far I've tried:

$node->taxonomy[$tid]->tid = $tid;
$node->taxonomy[$tid]->vid = $vid;
node_save($node);

But this doesn't seem to work, presumably because of the state the node object is in just as my action is being executed ($node is the result of calling node_load on the nid). I've also tried:

taxonomy_node_save($node, array($tid));

But this won't do it either. I don't get any error messages for either code snippets, but in both cases the node-term pair doesn't get added to the term_node database table.

Thank you in advance for your help.