Pages

Saturday 6 June 2015

Update Language Field of the single Content type

//print_r(allowips_for_role(5));
//$type= node_type_get_types();
//$fields = field_info_fields("node", "document");
 //echo "<pre>";
 //print_r($fields);
 //print_r($type);

$lang = und; // Replace with ISO639-2 code if localizing
$node_type = 'document'; // Machine name of the content type

$query = new EntityFieldQuery;
$result = $query
  ->entityCondition('entity_type', 'node')
  ->propertyCondition('type', $node_type)
  ->execute();

if (!empty($result['node'])) {
  $nodes = entity_load('node', array_keys($result['node']));

  foreach($nodes as $node) {
    // Replace field_foo with the machine name of the field to update.
    // - 0 refers to specific within the field array, for when the field contains
    //    multiple values. If the field only has one value, it should be 0.
//echo "<pre>";
//print_r($node->language);
     $node->language = 'en';
    node_save($node);
  }
}

No comments:

Post a Comment