Tuesday, December 24, 2013

Save node of Content Type Programatically

We can save a node of any content type programatically in Drupal It Rocks!!

 $node = new stdClass(); 

// Set content type
$node->type = 'product';
 
// Prepare defaults
node_object_prepare($node);

$node->language = LANGUAGE_NONE;
 
// Define language (currently language neutral)

 
// Basic content
$node->title = 'Save Content Type Node Programatically!!';
$node->body[$node->language][0]['value'] = 'Body text';

         //CCK or Added fields
$node->field_product_email[$node->language][0]['value'] = 'save@gmail.com';
 
// Save node
node_save($node);

No comments:

Post a Comment