I have this code in my module.
$node = new stdClass();
$node->title = "YOUR TITLE";
$node->type = "page";
node_object_prepare($node);
$node->language = 'it';
$node->uid = 1;
$node->status = 1;
$node->promote = 0;
$node->comment = 1;
$node = node_submit($node);
node_save($node);
return "Nodo 222: " . $node->nid;
When I execute this code, it returns "Nodo 222: XXX," where XXX is an integer. If I execute it another time, I get XXX+1. When I try to load node/XXX or node/XXX+1, Drupal give me a Page not found error.
I have seen the "node" table in MySQL (via PHPMyAdmin), and nids XXX and XXX+1 are not present. When I create a page via node/add/page, the new nid is XXX+2 and it is saved in the "node" table too.
I have some modules installed (commerce, rules, logintoboggan and others), but this is the first time that I see this strange behavior.
So, where is my error?
$node->is_new = TRUE;
? Is there anything in the logs?$node->body['it'][0]['value'] = 'Body goes here';
bit.ly/13iisqB