How to create a node programaticly in drupal5 (basic version)

Posted by: 
Dominique De Cooman

This piece of code imports a basic node into drupal.

function create_node() {
  $node_to_save = new stdClass();
  $node_to_save->nid = 0;
  $node_to_save->uid = 1;
  $node_to_save->type = 'product';
  $node_to_save->created = time();
  $node_to_save->title = 'title';
  $node_to_save->body = strval('body');
  $node_to_save->teaser = node_teaser($node->body);
  $node_to_save->filter = variable_get('filter_default_format', 1);
  $node_to_save->status = 1;
  //optional if you have cck fields do them this way
  $node_to_save->field_something = array(array('value' => 'something'));

Add new comment

Who are you?

By knowing who you are you will be directed to a page where we have displayed all our drupal services relevant to your professional identity.