I'm trying to programatically create, and add a term to a node. Here's what I've got so far:
function mymodule_nodeapi(&$node, $op, $teaser, $page) {
if($node->type == 'robot_club') {
switch ($op) {
case 'insert':
// create new taxonomy term
$termname = $node->title;
$term = array(
'vid' => 6, // Voacabulary ID - robot_clubs
'name' => $termname // Term Name
);
if (taxonomy_save_term($term)) {
$newterm = taxonomy_get_term_by_name($termname);
$node->taxonomy = $newterm;
} else {
drupal_set_message(t('Awwww snap! Something goofed up with adding the proper taxonomy terms to this club!', 'error'));
}
...
The term is created fine, but it isn't added to the node. Previously I tried taxonomy_node_save($node, $newterm)
, but that didn't work either. Help?