• Resolved DCuserName

    (@dcusername)


    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

    (@dcusername)

    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/

    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.

    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

    (@dcusername)

    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

    (@dcusername)

    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.