Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

Im trying to create a computed value field using the the computed_field module. I trying to do something like http://drupal.org/node/792922 but that example is for drupal 6. Can someone point me in the right direction of how to do this with drupal 7?

share|improve this question

1 Answer

up vote 2 down vote accepted

If you have taxonomy id, I'd suggest to do this:

$term = taxonomy_load_term($tid);
$node->your_field_name[your_language_specifier][your_value_index]['value'] = $term->name;

if you don't have taxonomy term id you can get it like so:

 $field_name = 'term'; //or what ever your field is named
 $entity_id = 4;//or what ever your entity id is   
 $query = db_select("field_data_field_" . $field_name, $field_name);
 $query->addField($field_name, "field_" . $field_name . "_tid", "tid");
 $query->condition("entity_id", $entity_id, "=");
 $result = $query->execute()->fetchAssoc();
 $tid = $result['tid'];
share|improve this answer
actually getting the taxonomy id from the entity is what I actually need the help with. – thargor Mar 6 '12 at 21:53
I updated the answer above with the code to get taxonomy id from an entity. – Alex Petrov Mar 6 '12 at 22:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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