Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I've created a Calendar view and I can add custom content types (with date field) to the calendar via the the Drupal administer overlay.
I'm now attempting to add the content node via php code (and set the date field) like this:
$node = new StdClass();
$node->type = 'event_2';
$node->title = t($tb2_event->name);
$node->field_event_date_2[LANGUAGE_NONE][0]['value'] = strtotime($tb2_event->start_time);
$node->field_event_date_2[LANGUAGE_NONE][0]['value2'] = strtotime($tb2_event->start_time);
$node->uid = $user->uid;
$node->status = 1;
$node->active = 1;
$node->promote = 1;
$node->comment = 1;
$node->created = strtotime("now");
node_submit($node);
node_save($node);
When I check back in Drupal Admin, I see that the Content has successfully been created, along with title and correct date. However, it does not show up in the Calendar until I hit the save button in Drupal Admin.
Can somebody please advise.
Thanks.
Comments
Comment #1
docteurdem CreditAttribution: docteurdem commentedI got the same issue by doing like you said, have any solution ?
$node->field_event_date_2[LANGUAGE_NONE][0]['value'] = strtotime($tb2_event->start_time);
$node->field_event_date_2[LANGUAGE_NONE][0]['value2'] = strtotime($tb2_event->start_time);
Comment #2
rudeboypeter CreditAttribution: rudeboypeter commentedAncient issue obviously, but just hit the same thing myself. Programmatically created nodes do not appear in Calendar views unless loaded and saved manually.