Title: Creating new events programatically
Last modified: January 26, 2019

---

# Creating new events programatically

 *  Resolved [DCuserName](https://wordpress.org/support/users/dcusername/)
 * (@dcusername)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/creating-new-events-programatically/)
 * I’m creating a custom form for visitors to submit events using Formidible Forms,
   then creating either an Event or Recurring Event draft post depending on their
   selections — I tried the EM front end submission form but I just think moany 
   of the options are too confusing for visitors, and the form template is more 
   work to edit than creating posts programmatically.
 * It all works, except that I can’t seem to set the start and end dates and times.
   I see them set correctly in the debug panel:
 * [event_start_time:protected] => 07:30
    [event_end_time:protected] => 09:00 [event_start_date:
   protected] => 2019-01-26 [event_end_date:protected] => 2019-01-31 [event_start:
   protected] => 2019-01-26 07:30 [event_end:protected] => 2019-01-31 09:00
 * But in the form, the start end end dates are blank and both times are set to 
   12:00.
 * If I set the fields in the form and submit, the values seem to be in the correct
   format, I don’t see a difference, but I must be missing something.
 * Actually I do see this later in the debug screen, maybe I need to set this also?
   I’m guessing that this needs an EM function call of some kind to set though:
 * [start:protected] => EM_DateTime Object
    ( [timezone_name:protected] => America/
   Los_Angeles [timezone_manual_offset:protected] => [valid] => [date] => 1970-01-
   01 00:00:00.000000 [timezone_type] => 3 [timezone] => America/Los_Angeles )
 * Thanks!
    David

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Thread Starter [DCuserName](https://wordpress.org/support/users/dcusername/)
 * (@dcusername)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/creating-new-events-programatically/#post-11134481)
 * Update — I found this page that shows code for creating events programmatically,
   and it’s working well for the most part:
 * [https://www.damiencarbery.com/2017/10/create-events-manager-events-programmatically/](https://www.damiencarbery.com/2017/10/create-events-manager-events-programmatically/)
 * But it only works for single events, not recurring. I tried adding this:
 * $EM_Event->recur = 1;
 * But the event still saves as a regular single event.
 * Maybe there’s a different save function for recurring events? This is what’s 
   used currently:
 * $EM_Event->save()
 * I haven’t found any documentation on this so far, hoping someone here knows.
 *  [Stonehenge Creations](https://wordpress.org/support/users/duisterdenhaag/)
 * (@duisterdenhaag)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/creating-new-events-programatically/#post-11134504)
 * Hi David,
 * A recurring event is a different custom post type than a single event, so a simple“
   recur= 1” will not work. Also the database references are quite different. You
   can take a look at the original code in events-manager/classes/em-event-post-
   admin.php
 *  Thread Starter [DCuserName](https://wordpress.org/support/users/dcusername/)
 * (@dcusername)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/creating-new-events-programatically/#post-11134533)
 * Doh! It needs to be:
 * $EM_Event->recurrence = 1;
 * Not:
 * $EM_Event->recur = 1;
 * Still some issues to iron out, but this works in principal!
 *  Thread Starter [DCuserName](https://wordpress.org/support/users/dcusername/)
 * (@dcusername)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/creating-new-events-programatically/#post-11134538)
 * Thanks Patrick — it actually works, it looks like the EM function looks for the
   recurrance flag and chooses the appropriate post type. Still some issues image,
   categories, etc., but much closer now…

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Creating new events programatically’ is closed to new replies.

 * ![](https://ps.w.org/events-manager/assets/icon-256x256.png?rev=3550347)
 * [Events Manager - Calendar, Bookings, Tickets, and more!](https://wordpress.org/plugins/events-manager/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/events-manager/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/events-manager/)
 * [Active Topics](https://wordpress.org/support/plugin/events-manager/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/events-manager/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/events-manager/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [DCuserName](https://wordpress.org/support/users/dcusername/)
 * Last activity: [7 years, 4 months ago](https://wordpress.org/support/topic/creating-new-events-programatically/#post-11134538)
 * Status: resolved