duplicate terms added by taxonomy_term_save Doesn't taxonomy_term_save() check if terms are being added in duplicate ? I have the following code -

function custom_create_taxonomy_term($name, $vid) {
  $term = new stdClass();
  $term-&gt;name = $name;
  $term-&gt;vid = $vid;
  taxonomy_term_save($term);
  return $term-&gt;tid;
}


But whenever I pass it a $name- which already exists in that vocabulary, then also a new entry is made in the database and there are 2 tids for the same term.
It's perfectly ok to have terms with the same name in the same vocabulary, the name column is not unique in the taxonomy_term_data table, and taxonomy_term_save() doesn't contain any logic to check.

This is by design as it would be very restrictive otherwise. Imagine you had a hierarchical vocab with many different levels...what happens if two terms happen to have the same name but live under different parents?

If you need your term names to be unique for whatever reason you can check if the term exists before saving it by using taxonomy_get_term_by_name()