1

I have a vocabulary with a field "legacy_id" which is a primary key another related system. I am building a routine to update the data in the drupal system based on changes in the related system. Other then hitting the DB directly, is there a way to retrieve the tid or the entire term from the field?

2

You can use EntityFieldQuery,

Here is the sample code,

$query = new EntityFieldQuery();

$query->entityCondition('entity_type', 'taxonomy_term')
  ->propertyCondition('vid', 1) // change 2 to any vocabulary ID
  ->fieldCondition('field_test', 'value', 'test');
$terms = $query->execute();

First param to fieldCondition is the field name, second one will be the column name for example for text fields column name is value and for term reference field tid, then the final one is to specify the value. Hope this helps.

1
  • Is ->entityCondition('bundle', 'voc_name') works as well instead of ->propertyCondition('vid', 1)?
    – kenorb
    Sep 29 '13 at 11:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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