Using EM_Event->save() does not publish event
-
I have a standalone script (WP_USE_THEMES = false) that adds an event by using EM_Event->save(). Unfortunately, although the event is saved and is in the back end and I can click ‘View’, it does not appear in the location page. If I Quick Edit and Update (no changes) it does appear.
When I look at the database the ‘event_slug’ column in ${prefix}_em_events table is NULL until I do the Quick Edit/Update.
My code does ‘wp_update_post()’ because the anonymous user is used to create the event because I am not logged in. That user cannot publish events.
Should I call EM_Event->save() again to set the slug again? I see that the EM code checks for an existing event and does some different stuff..
<?php define('WP_USE_THEMES', false); require( dirname( __FILE__ ) . '/wp-blog-header.php' ); $minute = date('i'); // Change the minute. $event_time = '18:'.$minute.':15'; $event_title = 'EM Test'; $event_end_date = '2017-02-10'; $EM_Event = new EM_Event(); $EM_Event->event_name = 'EM Test'; $EM_Event->event_slug = sanitize_title('EM Test 2017-02-10'); $EM_Event->post_content = "<p>This is the description of EM Test event on $event_date at $event_time.</p>"; $EM_Event->event_owner = 6; $EM_Event->location_id = 30; $EM_Event->event_start_date = '2017-02-10'; $EM_Event->event_end_date = '2017-02-10'; $EM_Event->event_start_time = '18:10:15'; $EM_Event->event_end_time = '18:10:15'; $EM_Event->start = strtotime($EM_Event->event_start_date.' '.$EM_Event->event_start_time); $EM_Event->end = strtotime($EM_Event->event_end_date.' '.$EM_Event->event_end_time); // Disable saving during development. $save_return = $EM_Event->save(); echo '<p>save() result: ', var_export($save_return, true), '</p>'; echo '<p>Event post ID: ', $EM_Event->post_id, '</p>'; echo '<p>Event event ID: ', $EM_Event->event_id, '</p>'; echo '<p>Minute: ', $minute, '</p>'; $args = array( 'ID' => $EM_Event->post_id, 'post_author' => 6, 'post_name' => sanitize_title('EM Test 2017-02-10'), 'post_status' => 'publish', ); wp_update_post( $args );
- The topic ‘Using EM_Event->save() does not publish event’ is closed to new replies.