I’m creating nodes automatically from xml, and I need to set the creation dates for them. I tried with
<?php
...
$node->created = $date //<- unix timestamp, $node is my node object
$node->changed = $other_date;
...
?>
but no luck, it sets the current date.
Any ideas?
Thanks
-edit-
$newNode = (object) NULL;
$newNode->type = 'blog';
$newNode->title = $title;
$newNode->uid = 1;
$newNode->status = 1;
$newNode->comment = 0;
$newNode->moderate = 0;
$newNode->sticky = 0;
$newNode->body['und'][0] = array(
'value' => $body,
'format' => 'full_html');
$newNode->log = 'Auto Imported Node';
$newNode->language = LANGUAGE_NONE;
// add fields
$newNode->field_description[LANGUAGE_NONE][0]['value'] = $description;
$newNode->field_byline[LANGUAGE_NONE][0]['value'] = $byline;
$newNode->field_small_image[LANGUAGE_NONE][0]['value'] = $smallimg;
$newNode->field_large_image[LANGUAGE_NONE][0]['value'] = $largeimg;
// save node
$newNode->created = $pd; // i've tried with commenting this line out, too
$newNode->date = $pd;
node_save($newNode);
It should work for
$node->created, but$node->changedcan’t be set with Drupal API.If you are using
node_submit()function which usesstrtotime($node->date)to set$node->created, you need to set$node->dateas a string date.