How to create nodes programmatically

<?php
$body_text = ‘This is the body text I want entered with the node.’;

$node = new stdClass();
$node->type = ‘product’;
node_object_prepare($node);

$node->title    = ‘Node Created Progr asim ammatically on ‘ . date(‘c’);
$node->language = LANGUAGE_NONE;

$node->body[$node->language][0][‘value’]   = $body_text;
$node->body[$node->language][0][‘summary’] = text_summary($body_text);
$node->body[$node->language][0][‘format’]  = ‘filtered_html’;

/* own fields start */

$node->field_status[$node->language][0][‘value’] = ‘0’; // cck field
$node->field_teachlang[$node->language][0][‘tid’] = 3;
$node->sell_price = 99;   // price
$node->model = ‘ggggg’;  // SKU
/* own fields end */

$path = ‘content/programmatically_created_node_’ . date(‘YmdHis’);
$node->path = array(‘alias’ => $path);

node_save($node);

?>

Was this article helpful?

Related Articles