1

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?

1 Answer 1

2

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'];
2
  • actually getting the taxonomy id from the entity is what I actually need the help with.
    – thargor
    Mar 6, 2012 at 21:53
  • I updated the answer above with the code to get taxonomy id from an entity. Mar 6, 2012 at 22:44

Your Answer

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

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