Forum

Thread tagged as: Question, Problem, Events

Past events continue to appear

Past events are not shown by default, to my knowledge. On a site I'm doing some maintenance for, there's a listing of upcoming events on the homepage using this array:

 <?php 
            $opts = array(
                'past-events'=>false,
                'category'=>array('events'),
                'sort'=>'eventDateTime',
                'sort-order'=>'asc',
                'template'=>'events/listing/event-day.html'
            );
            perch_events_custom($opts);

        ?>

The past events are showing, which is confusing the site's visitors. Here's the template for that area:

<perch:before>
<ul>
</perch:before>
  <li>
    <h5><span class="day"><perch:events id="eventDateTime" format="l, jS F Y" /></span></h5>
    <span class="time dtstart"><span class="value-title" title="<perch:events id="eventDateTime" format="c" />">   <perch:events id="eventDateTime" format="%l:%M %p" /></span> - </span>
    <span class="event summary <perch:events id="category_slugs" />"><a href="<perch:events id="eventURL" />"><perch:events id="eventTitle" /></a></span>
                <div class="description">
                    <perch:events id="eventDescHTML" encode="false" />
                </div>
  </li>

<perch:after>            
</ul>
</perch:after>

What's going on with it?

Gary Iverson

Gary Iverson 0 points

  • 7 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

the past-events filter is for the standard functions. You are using perch_events_custom so will need to filter what you show yourself (as is usual for any custom function). The docs are here: https://docs.grabaperch.com/docs/events/page-functions/custom/

You need to filter it via the date. i.e

$opts = array(
    'filter'=>'eventDateTime',
    'match'=>'gte',
    'value'=>date('Y-m-d'),
    'category'=>array('events'),
    'sort'=>'eventDateTime',
    'sort-order'=>'asc',
    'template'=>'events/listing/event-day.html'
);

Ah. So to make sure I'm understanding this properly, the above array will filter the events listing to include events that take place on a day that is either today or in future, correct?

Drew McLellan

Drew McLellan 2638 points
Perch Support

That's right.