How to list all the events taking place today from Event Espresso using Shortcode?

Photo of author
Written By geekerhub

Lorem ipsum dolor sit amet consectetur pulvinar ligula augue quis venenatis. 

What is the Event Espresso?
Event Espresso is a top-of-the-line event registration and ticketing management plugin for WordPress.
Since 2009, our purpose has been to empower business and organization leaders with the event registration and ticketing management tools that maximize the success of their events.

Event Espresso is a very flexible plugin for customization and their support is also too good.
We are going to create the shortcode, to list all the events taking place today. so we can replace/place shortcode anywhere where we need to show the Today’s Events.

You just need to place the shortcode “[EE_todays_events]” in a shortcode block to display today’s event.

Put below code snippets in your theme’s functions.php file and make sure the Event Espresso plugin is active.

We are using JSON API provided by the plugin to fetch all the events taking place today. Below code-snippet is self-explanatory for the developers. 🙂

function ee_rest_api_todays_events_callback( $atts ) {
    $atts = shortcode_atts( array(
        'url' => home_url()
    ), $atts, 'EE_todays_events' );

    $curdate = date("Y-m-d 00:00:00");
    $enddatec = date('Y-m-d H:i:s', strtotime('tomorrow'));
    if($atts['url'] == '') {
    $event_data_url = esc_url($atts['url']) . "/wp-json/ee/v4.8.36/events?calculate=image_medium_large&include=Datetime&where[Datetime.DTT_EVT_start][0]=BETWEEN&where[Datetime.DTT_EVT_start][1][]=" . urlencode($curdate) . "&where[Datetime.DTT_EVT_start][1][]=" . urlencode($enddatec);

    $json_data = file_get_contents($event_data_url, true); 
    $events = json_decode($json_data, true);  

    $html = '<div id="ee-events">';
    if ($events){
        foreach ($events as $event){
            $featured_image_url = $event['_calculated_fields']['image_medium_large']['url'];

            $html .= '<div class="ee-event">';
            $html .= '<h3><a href="' . $event[ 'link' ] . '">' . $event[ 'EVT_name' ] . '</a></h3>';
            $html .= '<div style="text-align:center">';
            $html .= $featured_image_url ? '<a href="' . esc_url( $event['link'] ). '"><img src="' . esc_url( $featured_image_url ) . '" /></a>' : '';
            $html .= '</div>';
            $html .= '<p>' . wp_trim_words($event[ 'EVT_desc' ]['rendered'], 55) . '&nbsp;<a href="' . $event[ 'link' ] . '">Read more</a></p>';
            $html .= '</div>';
    $html .= '</div>';
    return $html;
add_shortcode( 'EE_todays_events', 'ee_rest_api_todays_events_callback' );

Leave a Comment