Created
September 10, 2014 13:19
-
-
Save admataz/7cb85499e97d71087270 to your computer and use it in GitHub Desktop.
Drupal: Create a node programmatically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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