Drupal Version 6.
How to add/associate a term to a node using PHP? I use Computed Nodes, and I want to add a term to the node in some conditions. Detailed instructions would be appreciated. (Pay attention for Drupal 6, not 5)
I know I can solve the problem myself, but I'm bad in PHP and Drupal, and I need it very soon. Thanks a lot.

Comments

groovedork’s picture

I'm trying to learn how to do the same thing, but I'm not having much luck so far.

I suspect it's possible to add data to the $node array, and then when the user hits 'save' it also gets saved. Just quessing.

$node->taxonomy[0] = $TokenIDVariable;

RichardGv’s picture

I've tried this:
$node->taxonomy[] = $tid;
But that simply does not work.
I've also tried this:
$node->taxonomy[] = taxonomy_get_term($tid);
Not working, either.

RichardGv’s picture

I used the following piece of PHP, and it's working. I don't know if there are any bugs in it, though.

$node->taxonomy[] = $tid;
if(empty($node->build_type)) taxonomy_node_save($node, $node->taxonomy);

If there are any problems in this piece of PHP, please tell me, because I'm using the code on productive environment. Thanks.