I'm using this code in Rules, after saving a certain type of content, in execute custom PHP code. By now, i'm just trying to create anothe node of that type after the first is created. The problem is that this code creates a new node indeed, but without any custom fields. It has only language associated to it. Any idea on what's wrong? I followed the tutorial at http://fooninja.net/2011/04/13/guide-to-programmatic-node-creation-in-drupal-7/
$nodo = new stdClass(); // Create a new node object $nodo->type = "capitoli"; // Or page, or whatever content type you like node_object_prepare($nodo); // Set some default values $nodo->language = 'it'; // Or e.g. 'en' if locale is enabled $nodo->uid = $node->uid; // UID of the author of the node; or use $nodo->name $nodo->field_numero_capitolo[$nodo->language][0]['value']="2220"; $nodo->field_link[$nodo->language][0]['value']="aafafsf"; $path = 'node_created_on' . date('YmdHis'); // I prefer using pathauto, which would override the below path $nodo->path = array('alias' => $path); if($nodo = node_submit($nodo)) { // Prepare node for saving node_save($nodo); echo "Node with nid " . $nodo->nid . " saved!\n"; } If I replace
$nodo->language = 'it'; with
$nodo->language = LANGUAGE_NONE; this code create another node identical to the first one, not considering the values I used in the code and I can't figure out why.
EDIT: I tried doing as suggested in comments
$nodo->field_numero_capitolo['und'][0]['value']="2220"; $nodo->field_link['und'][0]['value']="aafafsf"; And it seems to work. What i did was to insert directly 'und'. Generally I think it is not a good idea to write directyl 'und', but these two fields are a link and a number, that should not change depending on language.