You are here

function taxonomy_term_check_term in Feeds 7

Checks whether a term identified by name and vocabulary exists. Creates a new term if it does not exist.

Parameters

$name: A term name.

$vid: A vocabulary id.

Return value

A term id.

1 call to taxonomy_term_check_term()
taxonomy_feeds_set_target in mappers/taxonomy.inc
Callback for mapping. Here is where the actual mapping happens.

File

mappers/taxonomy.inc, line 118
Mapper that exposes a node's taxonomy vocabularies as mapping targets.

Code

function taxonomy_term_check_term($name, $vid) {
  $terms = taxonomy_term_load_multiple(array(), array(
    'name' => $name,
    'vid' => $vid,
  ));
  if (empty($terms)) {
    $term = new stdClass();
    $term->name = $name;
    $term->vid = $vid;
    taxonomy_term_save($term);
    return $term->tid;
  }
  $term = reset($terms);
  return $term->tid;
}