Drupal 7 - Correctly go through all nodes of a type and save new data
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'congressperson')
->propertyCondition('status', 1);
$result = $query->execute();
if (!empty($result['node'])) {
$nids = array_keys($result['node']);
foreach ($nids as $nid) {
$node = node_load($nid, NULL, TRUE);
// do something awesome
/*
unset($node->field_bioguide_id[$node->language][0]);
unset($node->field_district[$node->language][0]);
unset($node->field_state[$node->language][0]);
*/
/*
$node->field_bioguide_id[$node->language][0]['value'] .= $bioguide;
$node->field_district[$node->language][0]['value'] .= $district;
*/
/*
$node->field_state[$node->language][0]['value'] = $state;
$node->field_party[$node->language][0]['value'] = $party;
*/
$node->field_chamber[$node->language][0]['value'] = $chambertitle;
// Make this change a new revision
$node->revision = 1;
$node->log = 'This node was programmatically updated at ' . date('c');
node_save($node);
}
}