Support

Home Forums Event Espresso Premium Add new event and register an attendee programmatically

Add new event and register an attendee programmatically

Posted: June 17, 2024 at 8:08 pm

Viewing 1 reply thread


c.barthe@futurelearning.fr

June 17, 2024 at 8:08 pm

I have to import a large number of events & associated attendees, so I am creating code to do this. Are you able to point me in the direction of any support/information/code that would help me achieve the creation of a new event, and/or registering a user to the event?

I am currently creating a new post with the post_type as espresso_events, then adding post_meta for the _EventStartDate and _EventEndDate but I am not sure if this is the correct way to do it?


c.barthe@futurelearning.fr

June 17, 2024 at 11:20 pm

Okay – I have progressed a little, and now using the event model. Is it possible to create events with the start and end dates in the past?

// Create the event
    $event = EE_Event::new_instance(array(
        'EVT_name' => wp_strip_all_tags($event_title),
        'EVT_desc' => $event_content,
        'EVT_slug' => $event_slug,
        'EVT_short_desc' => $event_excerpt,
        'EVT_wp_user' => $author_id,
    ));

    if ($event->save()) {
        $event_id = $event->ID();

        // Set the post status using WordPress functions
        wp_update_post(array(
            'ID' => $event_id,
            'post_status' => 'publish'
        ));

        // Create the datetime
        $datetime = EE_Datetime::new_instance(array(
            'EVT_ID' => $event_id,
            'DTT_EVT_start' => $formatted_start_date,
            'DTT_EVT_end' => $formatted_end_date,
            'DTT_reg_limit' => -1,
            'DTT_sold' => 0,
            'DTT_order' => 0,
        ));

        if ($datetime->save()) {
            // Link the datetime to the event
            $event->_add_relation_to($datetime, 'Datetime');
            echo "Event created successfully with ID: " . $event_id;
        } else {
            echo "Error saving datetime.";
        }
    } else {
        echo "Error creating event.";
    }
Viewing 1 reply thread

You must be logged in to reply to this support post. Sign In or Register for an Account

Event Espresso