I've got a list of terms which I need to add or update programmatically based on their name.

To check if the term exists I'm using a combination of taxonomy_vocabulary_machine_name_load to get the vid and taxonomy_get_term_by_name to get the term if exists. Otherwise I'm creating the term as stdClass object.

When I save the term normal field (using taxonomy_term_save) in format like $term->field_address[$term->language][]['value'] = 'some address data' everything works just fine, but when it comes to save relations nothing is begin saved.

I'm saving relations as $term->field_realization[$term->language][] = array( 'target_type' => 'taxonomy_term', 'value' => $another_term->tid);.

Where $term->language = 'und'; and $another_term is a term which belongs to right field Vocabulary declared in Administer.

What am I doing wrong?

  • What type of field are you using for your relations? Entity Reference or another one?
    – Zuzuesque
    Sep 28, 2015 at 16:59

1 Answer 1


If you're using the built-in term reference field type, the column is named tid, e.g.:

$term->field_realization[$term->language][]['tid'] = $another_term->tid;

If you're using an Entity Reference field type, the column is named target_id, e.g.:

$term->field_realization[$term->language][]['target_id'] = $another_term->tid;
  • but how to achieve mutiple values in this field?
    – roomcayz
    Sep 28, 2015 at 20:52
  • Sorry @Roomy, typo. I've updated the code
    – Clive
    Sep 28, 2015 at 21:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.