How to create a node programmatically
Submitted by valerio on Sun, 06/20/2010 - 10:56
// Create the node.
$node = array(
'title' => 'My Title',
'type' => 'my_type',
'body' => '',
'status' => 1,
'promote' => 0,
);
if ($node = node_submit($node)) {
$node->uid = 1; // set the user since we are running under cron
$node->newsletter_status = 'Preview Required';
$node->scheduled_send_date = date('Y-m-d H:i:s',$next_scheduled_send_date);
node_save($node);
$nid = $node->nid;
watchdog('An Identifier such as the module name', 'function_name: Created node'.$nid);
}else{
watchdog('An Identifier such as the module name', 'function_name: Failed to create node_type node',null, WATCHDOG_CRITICAL);
}
- Login to post comments