Support

Home Forums Event Espresso Premium How to hide past events on the My Events shortcode Reply To: How to hide past events on the My Events shortcode

Reply To: How to hide past events on the My Events shortcode

Author Replies
Josh # Posted on May 14, 2018 at 5:44 pm

The event date order is a bit of a tricky thing to order by because events can have multiple start dates (because an event can have multiple datetimes).

If you only have one datetime for an event, the following code can re-order the items by event start date. It can be added to the loop-espresso_my_events-event_section.template.php template.

Immediately after:
<?php if ($objects && reset($objects) instanceof EE_Event) : ?>
add:

<?php 
foreach ($objects as $object) :
    if (! $object instanceof EE_Event) {
        continue;
    }
    $datetimes = EEM_Datetime::instance()->get_datetimes_for_event_ordered_by_start_time( 
        $object->ID(), 
        false, 
        false, 
        10
    );
    $datetime = reset( $datetimes );
    $start = $datetime->get('DTT_EVT_start');
    $object->start = $start;
endforeach;
usort($objects, function($a, $b) {
    return strcmp($a->start, $b->start);
});
?>
Do NOT follow this link or you will be banned from the site!