Skip to content

Instantly share code, notes, and snippets.

@shrop
Last active December 20, 2015 07:58
Show Gist options
  • Save shrop/6096689 to your computer and use it in GitHub Desktop.
Save shrop/6096689 to your computer and use it in GitHub Desktop.
Create a node object and save it (Drupal 7)
<?php
$node = new stdClass();
$node->type = 'content_type';
$node->title = 'Node Title';
// Set the language.
$node->language = LANGUAGE_NONE;
// Custom field.
$node->field_custom[$node->$language][0]['value'] = 'Custom field data';
// Prepare and save the node.
node_object_prepare($node);
$node = node_submit($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