Skip to content

Instantly share code, notes, and snippets.

@shrop
Last active December 20, 2015 07:58
Show Gist options
  • Save shrop/6096753 to your computer and use it in GitHub Desktop.
Save shrop/6096753 to your computer and use it in GitHub Desktop.
Update a node object and save it (Drupal 7)
<?php
// Load a node with nid = 1000.
$node_nid = 1000;
$node = node_load($node_nid);
// Change the title of the node.
$node->title = 'New title';
// Update the value of a field with the language property of the node object.
$node->field_custom[$node->$language][0]['value'] = 'New custom field data';
// Set the revions property and save the updated node.
$node->revision = TRUE;
node_save($node);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment