Drupal 7 – Update node programmatically

If you want to update the node programmatically, the following example update the node title and the value of the custom field called field_example.

// Load the node with nid = 1
$nid = 1;
$a_node = node_load($nid);
$a_node->title = 'new title';
$a_node->field_example['und'][0]['value'] = 'new value';

// Save the node

// If you want to populate the node author and creation date, call node_submit() before saving
if($a_node = node_submit($a_node)) {
  // Save the node


Done =)

Reference: fooninja.net – Updating nodes programmatically in Drupal 7


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.