• Resolved Larry

    (@lpint)


    Thanks to gregoire1974 for creating the ep_simple_list shortcode. I am using it to show the “run” of shows (plays). As such I wanted some additional information printed.

    I have modified it slightly and am sharing the updated version. This version adds the event end date, can optionally include the organizer name and you can choose to use the event start date or end date to determine if the event is a past event.

    I’d like to add a link from the organizer name to the organizer page in event prime when the organizer is included, but seems to be above my very limited php abilities.

    To prevent mix-ups the original shortcode, I have named this version “ep_simple_list3”. Here’s the updated code:

    /**
    * Shortcode: [ep_simple_list3]
    * Displays a simplified list of EventPrime events, grouped into upcoming and past events.
    *
    * Shortcode attributes:
    * - type="" → event type slug (EventPrime taxonomy)
    * - limit=-1 → maximum number of events to display (-1 = no limit)
    * - order="DESC" → sorting order based on start date
    * - date="true" → display event date
    * - venue="true" → display event venue
    * - organizer="true" → display organizer
    * - upcoming=-1 → -1 = all events, 0 = past only, 1 = upcoming only
    * - date_test="start" → use "start" date or "end" date for upcoming test
    */

    function simple_eventprime_list3( $atts ) {
    /**
    * Define shortcode attributes and defaults.
    */
    $atts = shortcode_atts( array(
    'type' => '',
    'limit' => -1,
    'order' => 'DESC',
    'date' => 'true',
    'venue' => 'true',
    'organizer' => 'true',
    'upcoming' => -1, // Default: show both upcoming and past events
    'date_test' => 'start',
    ), $atts );

    /**
    * Query all EventPrime events.
    * We fetch all events and handle date filtering manually.
    */
    $args = array(
    'post_type' => 'em_event',
    'posts_per_page' => -1,
    'meta_key' => 'em_start_date_time',
    'orderby' => 'meta_value_num',
    'order' => $atts['order'],
    );

    /**
    * If an event type is provided, filter by taxonomy.
    */
    if ( ! empty( $atts['type'] ) ) {
    $args['tax_query'] = array(
    array(
    'taxonomy' => 'em_event_type',
    'field' => 'slug',
    'terms' => $atts['type'],
    ),
    );
    }
    $query = new WP_Query( $args );

    /**
    * Prepare arrays for upcoming and past events.
    */
    $now = current_time('timestamp');
    $upcoming_events = [];
    $past_events = [];

    /**
    * Retrieve the page used to display single EventPrime events.
    * Example: /all-events/?event=123
    */
    $listing_page = get_page_by_path('all-events');

    /**
    * Loop through events and separate them based on date.
    */
    if ( $query->have_posts() ) {
    while ( $query->have_posts() ) {
    $query->the_post();
    $event_id = get_the_ID();
    if ( $atts['date_test'] === "end" ) {
    $timestamp = get_post_meta( $event_id, 'em_end_date_time', true );
    } else {
    $timestamp = get_post_meta( $event_id, 'em_start_date_time', true );
    }
    if ( ! $timestamp ) continue;
    // Classify event as upcoming or past
    if ( $timestamp >= $now ) {
    $upcoming_events[] = $event_id;
    } else {
    $past_events[] = $event_id;
    }
    }
    }
    wp_reset_postdata();

    /**
    * Start output buffering to return clean HTML.
    */
    ob_start();

    /**
    * Helper function to output an event list section.
    */
    $display_events = function( $event_ids, $title ) use ( $atts, $listing_page ) {
    if ( empty( $event_ids ) ) return;
    // Section title (e.g., "Upcoming Performances")
    echo '<h5 style="font-weight:bold;">' . esc_html($title) . '</h5>';
    echo '<ul class="simple-eventprime-list">';
    $count = 0;
    foreach ( $event_ids as $event_id ) {
    // Apply "limit" attribute
    if ( $atts['limit'] > 0 && $count >= $atts['limit'] ) break;
    $count++;
    $event_title = get_the_title( $event_id );

    /**
    * Build event link
    * Preference: EventPrime listing page with ?event=ID
    * Fallback: event permalink
    */
    if ( $listing_page ) {
    $event_link = add_query_arg('event', $event_id, get_permalink($listing_page->ID));
    } else {
    $event_link = get_permalink($event_id);
    }
    echo '<li>';
    echo '<strong><a class="simple-eventprime-link" href="' . esc_url($event_link) . '"><em>' . esc_html($event_title) . '</em></a></strong>';

    /**
    * Display date if enabled.
    */
    if ( $atts['date'] === 'true' ) {
    $timestamp = get_post_meta( $event_id, 'em_start_date_time', true );
    if ( $timestamp ) {
    echo ': ' . date('m/d/Y', $timestamp) . ' ' ;
    }
    $timestamp = get_post_meta( $event_id, 'em_end_date_time', true );
    if ( $timestamp ) {
    echo ' - ' . date('m/d/Y', $timestamp) . ' ' ;
    }
    }

    /**
    * Display organizer if enabled.
    * Uses EventPrime taxonomy: em_event_organizer
    */
    if ( $atts['organizer'] === 'true' ) {
    $venue_terms = get_the_terms( $event_id, 'em_event_organizer' );
    if ( $venue_terms && ! is_wp_error( $venue_terms ) ) {
    $venue_name = implode( ', ', wp_list_pluck( $venue_terms, 'name' ) );
    echo ' presented by <b>' . esc_html( $venue_name ) . '</b>';
    }
    }

    /**
    * Display venue if enabled.
    * Uses EventPrime taxonomy: em_venue
    */
    if ( $atts['venue'] === 'true' ) {
    $venue_terms = get_the_terms( $event_id, 'em_venue' );
    if ( $venue_terms && ! is_wp_error( $venue_terms ) ) {
    $venue_name = implode( ', ', wp_list_pluck( $venue_terms, 'name' ) );
    echo ' at ' . esc_html( $venue_name ) . ' ';
    }
    }
    echo '</li>';
    }
    echo '</ul>';
    };

    /**
    * Display lists depending on "upcoming" attribute.
    */
    if ( $atts['upcoming'] == -1 ) {
    // Display both upcoming and past events
    $display_events( $upcoming_events, 'Upcoming Performances' );
    $display_events( $past_events, 'Past Performances' );
    } elseif ( $atts['upcoming'] == 1 ) {
    // Upcoming only
    $display_events( $upcoming_events, 'Upcoming Performances' );
    } elseif ( $atts['upcoming'] == 0 ) {
    // Past only
    $display_events( $past_events, 'Past Performances' );
    }

    /**
    * Fallback message if no events are found.
    */
    if ( empty($upcoming_events) && empty($past_events) ) {
    echo '<p class="simple-eventprime-none">No events found.</p>';
    }
    return ob_get_clean();
    }

    add_shortcode( 'ep_simple_list3', 'simple_eventprime_list3' );
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support epsupport1

    (@epsupport1)

    Thank you for sharing your updated ep_simple_list3 shortcode.

    To correctly link organizer names to their EventPrime organizer pages. Please replace your current code with the updated version shared below.

    /**
    * Shortcode: [ep_simple_list3]
    * Displays a simplified list of EventPrime events, grouped into upcoming and past events.
    *
    * Attributes:
    * – type=””
    * – limit=-1
    * – order=”DESC”
    * – date=”true”
    * – venue=”true”
    * – organizer=”true”
    * – upcoming=-1
    * – date_test=”start”
    */

    function simple_eventprime_list3( $atts ) {

    $atts = shortcode_atts( array(
    ‘type’ => ”,
    ‘limit’ => -1,
    ‘order’ => ‘DESC’,
    ‘date’ => ‘true’,
    ‘venue’ => ‘true’,
    ‘organizer’ => ‘true’,
    ‘upcoming’ => -1,
    ‘date_test’ => ‘start’,
    ), $atts );

    $args = array(
    ‘post_type’ => ’em_event’,
    ‘posts_per_page’ => -1,
    ‘meta_key’ => ’em_start_date_time’,
    ‘orderby’ => ‘meta_value_num’,
    ‘order’ => $atts[‘order’],
    );

    if ( ! empty( $atts[‘type’] ) ) {
    $args[‘tax_query’] = array(
    array(
    ‘taxonomy’ => ’em_event_type’,
    ‘field’ => ‘slug’,
    ‘terms’ => $atts[‘type’],
    ),
    );
    }

    $query = new WP_Query( $args );

    $now = current_time( ‘timestamp’ );
    $upcoming_events = array();
    $past_events = array();

    $listing_page = get_page_by_path( ‘all-events’ );

    if ( $query->have_posts() ) {
    while ( $query->have_posts() ) {
    $query->the_post();

    $event_id = get_the_ID();

    $timestamp = ( $atts[‘date_test’] === ‘end’ )
    ? get_post_meta( $event_id, ’em_end_date_time’, true )
    : get_post_meta( $event_id, ’em_start_date_time’, true );

    if ( ! $timestamp ) {
    continue;
    }

    if ( $timestamp >= $now ) {
    $upcoming_events[] = $event_id;
    } else {
    $past_events[] = $event_id;
    }
    }
    }
    wp_reset_postdata();

    ob_start();

    /**
    * Event list renderer
    */
    $display_events = function ( $event_ids, $title ) use ( $atts, $listing_page ) {

    if ( empty( $event_ids ) ) {
    return;
    }

    echo ‘<h5 style=”font-weight:bold;”>’ . esc_html( $title ) . ‘</h5>’;
    echo ‘<ul class=”simple-eventprime-list”>’;

    $count = 0;

    foreach ( $event_ids as $event_id ) {

    if ( $atts[‘limit’] > 0 && $count >= $atts[‘limit’] ) {
    break;
    }
    $count++;

    $event_title = get_the_title( $event_id );

    $event_link = $listing_page
    ? add_query_arg( ‘event’, $event_id, get_permalink( $listing_page->ID ) )
    : get_permalink( $event_id );

    echo ‘

    • ‘;
      echo ‘‘ . esc_html( $event_title ) . ‘‘;

      /* Date */
      if ( $atts[‘date’] === ‘true’ ) {
      $start = get_post_meta( $event_id, ’em_start_date_time’, true );
      $end = get_post_meta( $event_id, ’em_end_date_time’, true );

      if ( $start ) {
      echo ‘: ‘ . date( ‘m/d/Y’, $start );
      }
      if ( $end ) {
      echo ‘ – ‘ . date( ‘m/d/Y’, $end );
      }
      }

      /* Organizer (using EventPrime core function) */
      if ( $atts[‘organizer’] === ‘true’ && class_exists( ‘EventPrime_Basic_Functions’ ) ) {

      $basic = new EventPrime_Basic_Functions();

      $organizer_ids = get_post_meta( $event_id, ’em_organizer’, true );
      $organizers = ! empty( $organizer_ids )
      ? $basic->ep_get_event_organizer( $organizer_ids )
      : array();

      if ( ! empty( $organizers ) && is_array( $organizers ) ) {

      $links = array();

      foreach ( $organizers as $org ) {

      if ( ! empty( $org->name ) ) {

      if ( ! empty( $org->url ) ) {
      $links[] = ‘url ) . ‘”>’ . esc_html( $org->name ) . ‘‘;
      } else {
      $links[] = esc_html( $org->name );
      }
      }
      }

      if ( ! empty( $links ) ) {
      echo ‘ presented by <b>’ . implode( ‘, ‘, $links ) . ‘</b>’;
      }
      }
      }

      /* Venue */
      if ( $atts[‘venue’] === ‘true’ ) {
      $venue_terms = get_the_terms( $event_id, ’em_venue’ );
      if ( $venue_terms && ! is_wp_error( $venue_terms ) ) {
      echo ‘ at ‘ . esc_html( implode( ‘, ‘, wp_list_pluck( $venue_terms, ‘name’ ) ) );
      }
      }

      echo ‘

    • ‘;
      }

      echo ‘‘;
      };

      if ( $atts[‘upcoming’] == -1 ) {
      $display_events( $upcoming_events, ‘Upcoming Performances’ );
      $display_events( $past_events, ‘Past Performances’ );
      } elseif ( $atts[‘upcoming’] == 1 ) {
      $display_events( $upcoming_events, ‘Upcoming Performances’ );
      } else {
      $display_events( $past_events, ‘Past Performances’ );
      }

      if ( empty( $upcoming_events ) && empty( $past_events ) ) {
      echo ‘<p class=”simple-eventprime-none”>No events found.</p>’;
      }

      return ob_get_clean();
      }

      add_shortcode( ‘ep_simple_list3’, ‘simple_eventprime_list3’ );

    Thread Starter Larry

    (@lpint)

    Thank you for the updated shortcode. I am having a slight issue with it, however. The end date is displaying as one day after the end date set in the event setting. Any ideas as to why this might be?

    The original em_simple_list3 that I submitted has the same problem, so it was not introduced by your update. I just can’t understand why the end date is showing one day after the end date set for the event!?!

                $start = get_post_meta( $event_id, 'em_start_date_time', true );
                $end   = get_post_meta( $event_id, 'em_end_date_time', true );
    
                if ( $start ) {
                    echo ': ' . date( 'm/d/Y', $start );
                }
                if ( $end ) {
                    echo ' - ' . date( 'm/d/Y', $end );
                }

    Here’s the link to the page that is showing the issue: https://mn-act.net/ep-events-calendar/upcoming-shows-list/ If you click on one of the events you can see that the end date set for the event is one day earlier than the end date shown in the list.

    Plugin Support epsupport1

    (@epsupport1)

    Thank you for sharing the details and the code snippet.

    We have reviewed this at our end, and the behavior you’re seeing is expected when using PHP’s date() function directly with EventPrime timestamps. The issue occurs because EventPrime stores event date/time values as Unix timestamps while date() does not fully respect WordPress timezone settings. As a result, the end date may appear shifted by one day.

    To resolve this, we recommend using WordPress’s wp_date() function instead of date(), as wp_date() correctly applies the site’s timezone and localization settings.

    Please update your code as shown below:

    $start = get_post_meta( $event_id, 'em_start_date_time', true );$end   = get_post_meta( $event_id, 'em_end_date_time', true );
    if ( $start ) {
        echo ': ' . wp_date( 'm/d/Y', $start );
    }
    if ( $end ) {
        echo ' - ' . wp_date( 'm/d/Y', $end );
    }

    After making this change, the end date displayed in the list should correctly match the end date configured in the event settings.

    Thread Starter Larry

    (@lpint)

    That solved the problem. Thank you for your always great support.

    Plugin Support epsupport1

    (@epsupport1)

    Thanks for the update.

    If you have any further questions, please don’t hesitate to reach out to us.

Viewing 5 replies - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.