Sorry if this is a duplicate.
GOAL: when a user selects a taxonomy from a field, add the parent nodes for that field as well.
The Rule
EVENT
After saving new content
After updating existing content
CONDITIONS (optional)
Content is of type (your node type)
ACTION
Execute custom PHP code
The code
[code]
$parents=taxonomy_get_parents_all($node->field_location['und'][0]['tid']); //gets all parents and self for the term added
$t=array();
foreach($parents as $p){
$t[]=get_object_vars($p); //convert the objects to arrays
}
$node->field_termReferenceField['und']=$t; //overwrite the field termReferenceField would be your field name
node_save($node); //save the node
[/code]
I hope this helps someone.
