Adding taxonomy

There are two types of terms to add. The folksonomy 'tag' type, which can just take a comma separate string per vocabulary id vid:-

  // $user['languages'] and $user['other_expertise'] incoming array of term titles
  $user['languages'] = implode(',',unserialize($user['languages']));
  $user['other_expertise'] = str_replace('other?', '', $user['other_expertise']);
  // 10 and 11 the vocabulary ids
  $node->taxonomy['tags'] = array('10' => $user['other_expertise'], '11' => $user['languages']);

and those with terms already entered with a term id tid. For these a lookup table worked well:-

  $node->taxonomy += _x_taxonomy_ctype($xc['content_type']);

function _x_taxonomy_ctype($ctype) {
  $lookup = array(
    // string from the post being migrated => tid
    'resource' => 59,
    'result' => 1210,
    'results' => 1210,
    'training' => 58,
  );
  // return vocabulary id 'vid' => array()
  return array( '7' => _x_taxonomy_lookup($ctype, $lookup));
}

function _x_taxonomy_lookup($items, $lookup) {
  if (! is_array($items)) {
    $terms = $lookup[$items];
  }
  else {
    foreach ($items as $i) {
      $terms[$lookup[$i]] = $lookup[$i];
    }
  }
  return $terms;
}