I'd like to allow a module to modify a $node to add a new free tag term as the node is being created.

I understand how to add a pre-existing term to the node, but I'm unsure as to the best way to add a new free tag (based on a dynamically created string).

I get the impression that if the vid for the freetagging vocabulary is 3, then the code should be

$new_term = array('name' => 'new free tag term', 'vid' => 3);
$node->taxonomy[] = $new_term;

That doesn't seem to work. Instead, it just adds term id 3 to the taxonomy, event though I specified a vid rather than tid.

I've read through the taxonomy handbook and forums pretty extensively, but I wasn't able to find the answer.

Any help would be greatly appreciated!

Comments

piersonr’s picture

Thanks to Heine, here's the correct code:

$node->taxonomy['tags'][$vid] = $tags;

where $vid is the number of the vocabulary id and $tags is a comma delimited string of tags to add