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‘ – 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.