Creating nodes programmatically in Drupal (including cck and location fields)
Creating a new node in drupal is trivial, but when the node includes custom cck fields, then a few things can trip you up. To save time and energy, here’s a quick guide and some tips to make your drupal life easier. Creating a basic node: global $user; //get current logged in user $new_node = new stdClass(); $new_node->type = 'YOUR_NODE_TYPE_HERE'; $new_node->uid = $user->uid; //you can specify some other userID here if you want $new_node->name = $user->name; $new_node->title = $YOUR_NODE_TITLE; $new_node->body = $YOUR_NODE_BODY; $new_node->status = 1; // published node_save($new_node); The function node_save() does a few things behind the scene. It checks if the nid property is empty to determine if this is a new insert or an update, then calls the appropriate functions so that you would not have duplicates. Put simply, if you want to do an update, populate the nid, and leave it out otherwise. Creatnig a node with CCK fields involves ...