How to update some field of all article nodes programatically and set it equal to its title? I have a field name 'field_new' in a content type 'article'. I want to insert the value of node title on this field (all the nodes) programatically.

What I have done to achieve, I am using hook_node_update for this, but it is not updating the field values.

function modulename_node_update($node) {
  $new_value = $node-&gt;title;
  $node-&gt;field_new[LANGUAGE_NONE][0]['value'] = $new_value;
  field_attach_update('node', $node);
}


It would be great if there are another alternatives to do this.
hook_node_update - Respond to updates to a node. This is useful when you wants to update a field during node save. This will not helpful in this case because you wants to update all your exiting nodes.

1.Hope this code will helps you. 
You will get an idea but this is not the exact code for copy and paste.

&lt;?php
    // Get all nodes of 'article' type, populate the field with a value of '1'.
    $articles = db_query("SELECT nid, vid FROM {node} WHERE type = 'article'")-&gt;fetchAllAssoc('nid');
    foreach ($articles as $nid =&gt; $values) {
      $fields = array(
        'entity_type' =&gt; 'node',
        'bundle' =&gt; 'article',
        'deleted' =&gt; 0,
        'entity_id' =&gt; $values-&gt;nid,
        'revision_id' =&gt; $values-&gt;vid,
        'language' =&gt; LANGUAGE_NONE,
        'delta' =&gt; 0,
        'field_data_field_new' =&gt; 'title need to fetch',
      );
      db_insert('field_data_field_new') //data table name
        -&gt;fields($fields)
        -&gt;execute();
      db_insert('field_revision_field_data_field_new') //revision table name
        -&gt;fields($fields)
        -&gt;execute();
    }
    ?&gt;



Another suggestion is Views Bulk Operations (VBO). You need investigate on it. 
Bulk field update?
Updating a single field value for a particular content type:




 $article_nodes = node_load_multiple(array(), array('type' =&gt; 'article'));
    foreach ($article_nodes as $article_node) {
          $article_node-&gt;field_new[LANGUAGE_NONE][0]['value'] = 'title value';
          field_attach_update('node', $article_node);
        }