Created
October 27, 2010 14:54
-
-
Save semperos/649181 to your computer and use it in GitHub Desktop.
Create simple node programmatically
This file contains hidden or 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 | |
/** | |
* Programmatic creation of a node - as simple as it gets | |
* | |
* All Drupal nodes require a title; everything is else is optional or | |
* is auto-generated by Drupal upon saving the node to the database. | |
* This node has no extra CCK fields defined; we're simply giving it | |
* a title and a body. The author will be the super-admin user, and its | |
* published status will be "published". | |
*/ | |
// Create an empty object | |
$node = new stdClass; | |
// Setup the basics | |
$node->uid = 1; | |
$node->status = 1; | |
$node->type = 'page'; | |
// Fill in the data | |
$node->title = 'Results for submission ' . $something_unique_here; | |
$node->body = 'Results: ' . $body_of_results; | |
// Submit the node, so validation is run | |
$node = node_submit($node); | |
// Save the now-validated node to the database | |
node_save($node); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment