How to list all the events of Event Espresso from offsite 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 “[event_from_offsite]” in a shortcode block to display events from offsite.

Put below code snippets in your theme’s functions.php file. We are using JSON API provided by the plugin to fetch all the events from another site. Below code, snippets are self-explanatory for the developers. 🙂

function event_from_offsite_callback( $atts ) {
    $atts = shortcode_atts( array(
        'url' => ''
    ), $atts, 'event_from_offsite' );

    $current_date = date("Y-m-d H:i:s");

    /*If there is no offsite URL, then return*/
    if($atts['url'] == '') {

    $data_url = esc_url($atts['url']) . "/wp-json/ee/v4.8.36/events?calculate=image_medium_large&include=Datetime&where[Datetime.DTT_EVT_start][]=>&where[Datetime.DTT_EVT_start][]=" . urlencode($current_date);
    $json = file_get_contents($data_url, true); 
    $events = json_decode($json, true); 
    $count = count( $events ); 

   $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( 'event_from_offsite', 'event_from_offsite_callback' );

Leave a Comment