You only need 4 pieces of information to create an Events Manager event in PHP. This is the core of the code I use in a nightly event import script on a client site.
On Cork Entertainment, a client site that lists events in Cork in Ireland, I run a script each night to scrape data from the website of one venue (with the venue owner’s permission). The client site uses the Events Manager plugin so it needs to create events dynamically.
Events Manager uses the event title and content to create a post of type ‘event.’ It then stores the event details (date, time, location etc) as post meta.
Only 4 items of information to create an event – name, post content, start date and start time.
The date and time formats are simple: yyyy-mm-dd and hh:mm:ss.
The script below, a standalone one, goes a step further – after the event is created it changes the default slug, which is based on the event name, to one based on a concatenation of the event name and date. This was useful on the Cork Entertainment site because bands play more than once and slugs with numerical suffixes e.g. -2 or -3 etc., don’t look good. The code uses ‘em_event_save‘ filter – it changes the slug, author (from the anonymous one that would leave the event status as ‘Pending’) and the status to ‘Publish.’ Removing the filter is not necessary in this script but included for completeness. The same filter is used by the plugin when saving other post types so one needs to be careful when using it.
This code works perfectly as the core code for the nightly script and imports events as necessary.
Update 10 January 2018: Early in December the nightly script stopped adding events. The events appeared in the dashboard but not on the front end. It worked with Events Manager 5.7.3 but not in version 5.8.x. The required row was not being created in the event table.
I reported the issue to the developers and I did a lot of debugging, stepping through the code. Eventually I saw an error message related to the ‘event_rsvp‘ database column – it was not being initialised by Event Manager. My fix was to set it in my code:
$EM_Event->event_rsvp = false;. I posted this info to the support thread.