Skip to content

Instantly share code, notes, and snippets.

@admataz
Created September 10, 2014 13:19
Show Gist options
  • Save admataz/7cb85499e97d71087270 to your computer and use it in GitHub Desktop.
Save admataz/7cb85499e97d71087270 to your computer and use it in GitHub Desktop.
Drupal: Create a node programmatically
<?php
function make_node_programmatically()($title) {
global $user;
$node = new stdClass(); // We create a new node object
$node->type = "pages"; // Or any other content type you want
$node->title = $title;
$node->language = LANGUAGE_NONE;
node_object_prepare($node); // Set some default values.
$node->uid = $user->uid; // Or any id you wish
$node = node_submit($node); // Prepare node for a submit
node_save($node); // After this call we'll get a nid
return $node->nid;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment