Create a gist now

Instantly share code, notes, and snippets.

Front-end event creation with Event Organiser
* This is a basic example of implementing front end creation of events with Event Organiser
* @see
* @see
function my_event_form_shortcode_handler( ){
if( !is_user_logged_in() ){
return '<p> Only logged in users can post events </p>';
$html = '<form method="POST">';
//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" >
'Event 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"></textarea>
'Event Description'
//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" >
'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" >
'End Date'
$html .= sprintf('<p><label for="my-frontend-event-%1$s"> %2$s %3$s </label></p>',
'orderby' => 'ID',
'order' => 'ASC',
'hide_empty' => 0,
'echo' => 0,
'name' => 'my_frontend_event[venue]',
'taxonomy' => 'event-venue'
//Category - checklist
$cats = get_terms('event-category',array('hide_empty'=>0));
if( $cats ){
$html .= '<p><label for="my-frontend-event-category">Category <ul>';
foreach ( $cats as $cat ){
$html .= sprintf('<li><label for="my-frontend-event-%1$s-%2$d">
<input type="checkbox" name="my_frontend_event[%1$s][]" value="%2$s" id="my-frontend-event-%1$s-%2$d" >
$html .= '</label></p>';
//The post button
$html .= '<p><input name="submit" type="submit" id="submit" value="Post Event"></p>';
$html .='</form>';
return $html;
function my_frontend_event_post_listner(){
if( !isset($_POST['my-action']) || 'post-event' != $_POST['my-action'] )
//Collect raw input
$input = $_POST['my_frontend_event'];
//Check user is logged in:
if( !is_user_logged_in() )
//Check nonce
check_admin_referer( 'post-event', '_mynonce');
* IMPORTANT: Perform any other checks you need to here (e.g. should only users with a certain capability be able to post events?)
* Set the post data (see
* This includes event-category and event-venue (taxonomy terms)
//Event venue is just an ID
$event_venue = (int) isset($input['venue']) ? $input['venue'] : 0;
//Event cats are an array of IDs
$event_cats = isset($input['category']) ? $input['category'] : array();
$event_cats = array_map('intval',$input['category']);
$post_data =array(
* 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' => 1, //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.
$post_id = eo_insert_event($post_data,$event_data);
HandHugs commented Jan 4, 2014

This all works great except for the venues for me - when they click to post the event, it creates a new venue with no information except a title that is the ID of the venue that was selected when they submitted the event, rather than matching them up and using the venue they selected.

The venue is also a little limiting since they cannot add new ones, it might be nice to have an option for just "none" so they aren't forced to pick a venue that is incorrect.


Hi @HandHugs this gist is now being maintained here: (which has now been corrected). I'll update the tutorial too.

It's entirely possible to select 'no venue' - see the codex for the wp_dropdown_categories() function used to produce the drop-down menu of venues. Specifically the show_option_none argument.

As for creating new venues, this is entirely possible to (see the documentation of eo_insert_venue(): This was just a simple example to demonstrate what you can do.

The front-end submission extension shall include the ability to accept new venues. You'll be able to create your own form by adding various fields (event name, date, recurrence schedule, venues, categories and other fields for meta data) as desired and then use drag-and-drop to order them as required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment