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