Just unset the node ID with unset($node->nid)
, and node_save() will create a new node.
The code executed from node_save()
is the following one:
// Insert a new node.
$node->is_new = empty($node->nid);
// ...
if ($node->is_new) {
_node_save_revision($node, $user->uid);
drupal_write_record('node', $node);
db_query('UPDATE {node_revisions} SET nid = %d WHERE vid = %d', $node->nid, $node->vid);
$op = 'insert';
}
The last argument of drupal_write_record() is not passed; this means the function will not update an existing database row.
Once the node object has been saved with node_save()
, $node->nid
contains the node ID for the newly created database row.