Update Event
-
Hi,
Working from this tutorial (which works great)
http://www.stephenharris.info/2012/front-end-event-posting/But trying to to update posts as well… all working except that cant figure why the dates are not being saved in the format: 16-Jul-2013 12:00am doesnt datetime obj dupport that?
<?php /** * This is a basic example of implementing front end creation of events with Event Organiser * @see http://www.stephenharris.info/2012/front-end-event-posting/ * @see http://wordpress.org/extend/plugins/event-organiser/ * */ add_shortcode('my_event_form','my_event_form_shortcode_handler'); function my_event_form_shortcode_handler( ){ if( !is_user_logged_in() ){ return '<p> Only logged in users can post events </p>'; } // =T. Get Post Data for Event Updates $event_id = $_GET['event_id']; // get event id form url like url?event_id $event_post = $event_id ? get_post($event_id) : null; $event_start_date = eo_get_schedule_start( 'd-M-Y h:ia', $event_id ); $event_end_date = eo_get_schedule_last('d-M-Y h:ia', $event_id ); // The form $html .= '<form method="POST">'; // pass event_id if updating and event $html .= $event_id ? '<input type="hidden" name="my_frontend_event[event_id]" value="'.$event_id.'" >' : ''; //Create hidden 'action' field and corresponding nonce $html .= '<input type="hidden" name="my-action" value="post-event" >'; $html .=wp_nonce_field( 'post-event', '_mynonce',false,false); //Event Title $html .= sprintf('<p><label for="my-frontend-event-%1$s"> %2$s <input type="text" name="my_frontend_event[%1$s]" id="my-frontend-event-%1$s" value="%3$s"> </label></p>', 'title', 'Event Title', $event_post->post_title ); //Event Description $html .= sprintf('<p><label for="my-frontend-event-%1$s"> %2$s <textarea name="my_frontend_event[%1$s]" id="my-frontend-event-%1$s">%3$s</textarea> </label></p>', 'description', 'Event Description', $event_post->post_content ); //Start date $html .= sprintf('<p><label for="my-frontend-event-%1$s"> %2$s <input type="text" name="my_frontend_event[%1$s]" id="my-frontend-event-%1$s" class="my-frontend-event-datepicker" value="%3$s" > </label></p>', 'startdate', 'Start Date', $event_start_date ); //End date $html .= sprintf('<p><label for="my-frontend-event-%1$s"> %2$s <input type="text" name="my_frontend_event[%1$s]" id="my-frontend-event-%1$s" class="my-frontend-event-datepicker" value="%3$s" > </label></p>', 'enddate', 'End Date', $event_end_date ); //The post button $html .= '<p><input name="submit" type="submit" id="submit" value="Post Event"></p>'; $html .='</form>'; return $html; } add_action('init','my_frontend_event_post_listner'); function my_frontend_event_post_listner(){ if( !isset($_POST['my-action']) || 'post-event' != $_POST['my-action'] ) return; //Collect raw input $input = $_POST['my_frontend_event']; //Check user is logged in: if( !is_user_logged_in() ) return; //Check nonce check_admin_referer( 'post-event', '_mynonce'); $post_data =array( 'post_title'=>$input['title'], 'post_content'=>$input['description'], 'post_status' => 'pending' ); /** * Set the event data */ //Start and end dates need to be given as DateTime objects (timezone is UTC unless a timezone is given) $start = new DateTime($input['startdate'], eo_get_blog_timezone()); $end = new DateTime($input['enddate'], eo_get_blog_timezone()); $event_data =array( 'schedule' =>'once', //specifies the reoccurrence pattern 'all_day' => 0, //1 if its an all day event, 0 if not - if not you'll need to specify a start/end time for the DateTimeobjects 'start' => $start, //start date (of first occurrence) as a datetime object 'end' => $end, //end date (of first occurrence) as a datetime object ); //Finally, Insert event. if ($input['event_id']) { $post_id = eo_update_event($input['event_id'], $event_data, $post_data ); } else { $post_id = eo_insert_event ($post_data,$event_data); } if ($post_id) { wp_redirect( home_url('/dashboard/my-events')); exit; } } ?>
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Update Event’ is closed to new replies.