Update Drupal node programmatically, add node to taxonomy term

[b]How to update Drupal node  programmatically, from your PHP script using Drupal API[/b]

This example function will update node and add it to the desired taxonomy term.


function add_teasers_to_term($tid, $nid){

 $node = node_load($nid);
 
 // we need to check if node is in the taxonomy already, so build array of term ids for this node
 foreach($node->taxonomy as $key=>$value){
   $nodes_taxonomy[] =  $key;
 }
 
 print_r($nodes_taxonomy);
 // first check if node is already in there
 if (in_array($tid, $nodes_taxonomy)){
    return ' node already in '.$nid;
 }
 else {
   $node->taxonomy[] = $tid;
   node_save($node);
    return ' node saved '.$nid;
 }

}