Last spring I was able to achieve my need of hiding expired events via the ESPRESSO_MY_EVENTS shortcode and some custom code in two php template files. At some point since then however, an update somewhere broke the solution. I’m trying to recreate what I did the first time, but experiencing some errors I can’t get past.
Here’s what I currently have…
On the user’s profile page is the shortcode:
[ESPRESSO_MY_EVENTS template=simple_list_table your_events_title=’Upcoming Live Training Events For Which You Are Currently Registered’]
The content-espresso_my_events-simple_list_table.template.php code looks like this:
The loop-espresso_my_events-simple_list_table.template.php code looks like this;
<?php
/**
* Template for the "simple_list_table" loop template for the [ESPRESSO_MY_EVENTS] shortcode
*
* Available template args:
* @type string $object_type The type of object for objects in the 'object' array. It's expected for this template
* that the type is 'Registration'
* @type EE_Registration[] $objects
* @type int $object_count Total count of all objects
* @type string $your_events_title The default label for the Events section
* @type string $your_tickets_title The default label for the Tickets section
* @type string $template_slug The slug for the template. For this template it will be 'simple_list_table'
* @type int $per_page What items are shown per page
* @type string $path_to_template The full path to this template
* @type int $page What the current page is (for the paging html).
* @type string $with_wrapper Whether to include the wrapper containers or not.
* @type int $att_id Attendee ID all the displayed data belongs to.
*/
$url = EEH_URL::current_url();
$pagination_html = EEH_Template::get_paging_html(
$object_count,
$page,
$per_page,
$url,
false,
'ee_mye_page',
array(
'single' => __( 'event', 'event_espresso' ),
'plural' => __( 'events', 'event_espresso' )
));
?>
<?php if ( $with_wrapper ) : ?>
<div class="espresso-my-events <?php echo $template_slug;?>_container">
<?php do_action( 'AHEE__loop-espresso_my_events__before', $object_type, $objects, $template_slug, $att_id ); ?>
<h3><?php echo $your_events_title; ?></h3>
<div class="espresso-my-events-inner-content">
<?php endif; //$with_wrapper check ?>
<?php if ( $objects && reset( $objects ) instanceof EE_Registration ) : ?>
<table class="espresso-my-events-table <?php echo $template_slug;?>_table">
<thead>
<tr>
<th scope="col" class="espresso-my-events-reg-status ee-status-strip">
</th>
<th scope="col" class="espresso-my-events-event-th">
<?php echo apply_filters(
'FHEE__loop-espresso_my_events__table_header_event',
esc_html__( 'Title', 'event_espresso' ),
$object_type,
$objects,
$template_slug,
$att_id
); ?>
</th>
<th scope="col" class="espresso-my-events-ticket-th">
<?php echo apply_filters(
'FHEE__loop-espresso_my_events__table_header_ticket',
esc_html__( 'Start Date & Time', 'event_espresso' ),
$object_type,
$objects,
$template_slug,
$att_id
); ?>
</th>
<th scope="col" class="espresso-my-events-location-th">
<?php echo apply_filters(
'FHEE__loop-espresso_my_events__location_table_header',
esc_html__( 'Location', 'event_espresso' ),
$object_type,
$objects,
$template_slug,
$att_id
); ?>
</th>
<th scope="col" class="espresso-my-events-actions-th">
<?php echo apply_filters(
'FHEE__loop-espresso_my_events__actions_table_header',
esc_html__( 'Actions', 'event_espresso' ),
$object_type,
$objects,
$template_slug,
$att_id
); ?>
</th>
</tr>
</thead>
<tbody>
<?php foreach ( $objects as $object ) {
if ( ! $object instanceof EE_Registration ) {
continue;
}
$template_args = array( 'registration' => $object );
$template = 'content-espresso_my_events-simple_list_table.template.php';
EEH_Template::locate_template( $template, $template_args, true, false );
} ?>
</tbody>
</table>
<div class="espresso-my-events-footer">
<div class="espresso-my-events-pagination-container <?php echo $template_slug;?>-pagination">
<span class="spinner"></span>
<?php echo $pagination_html; ?>
<div style="clear:both"></div>
</div>
<div style="clear:both"></div>
<?php EEH_Template::locate_template( 'status-legend-espresso_my_events.template.php', array( 'template_slug' => $template_slug ), true, false ); ?>
</div>
<?php else : ?>
<div class="no-events-container">
<p><?php echo apply_filters(
'FHEE__loop-espresso_my_events__no_events_message',
esc_html__( 'You have no registrations yet', 'event_espresso' ),
$object_type,
$objects,
$template_slug,
$att_id
); ?>
</p>
</div>
<?php endif; ?>
<?php if ( $with_wrapper ) : ?>
</div>
<?php do_action( 'AHEE__loop-espresso_my_events__after', $object_type, $objects, $template_slug, $att_id ); ?>
</div>
<?php endif; //end $wrapper check?>
However, with that shortcode and template file code, I’m still seeing all the events for which a person is registered – not just the future events. What am I missing?
That error is basically saying $event doesn’t exist and calling get_active_status() on $event throws a fatal because $event is NULL and so have no methods to call.
So right now it seems your above templates are actually loading (otherwise you’d be getting the same error), or you have an older version of the WP User integration add-on that does pass the event object over.
Which version number of the WP User integration add-on are you using?
Where are those 2 above template files located on your site?
We can fix the template to stop it loading past events, however, right now it appears your site isn’t actually loading those templates so lets get that working first.
I have EE-WP Users (EE4.6+) version 2.0.16.p installed, but I don’t know how to tell if the template is loading. But I’m not getting an error on the loaded page.
The two php files are located in public_html/lms/wp-content/plugins/themes/education-zone-child, and I edit them via the WP Menu -> Appearance -> Editor.
I’ve just tried to view your site but the domain linked to your account redirects to a youtube video, just noting in case that’s not expected.
I have EE-WP Users (EE4.6+) version 2.0.16.p installed, but I don’t know how to tell if the template is loading. But I’m not getting an error on the loaded page.
The easiest way is to just add some additional content to the template and see if that’s output, so above the check I mentioned earlier you could add something like:
The only reason the site would redirect is if your IP is outside the U.S. If send me your IP (via DM or email) I can whitelist it. I can also send you site login credentials.
Tried the echo test and indeed it does not appear the custom template file is loading. So… what next?
The only reason the site would redirect is if your IP is outside the U.S. If send me your IP (via DM or email) I can whitelist it.
Yeah, that’s why, I’m in the UK.
If send me your IP (via DM or email) I can whitelist it.
I’ll put my IP in a private reply right after this one.
I’m a little stumped as to why/how that’s working tbh, it shouldn’t be.
I can see in one of your other threads HERE that you also have that code in content-espresso_my_events-event_section.template.php which does make sense as the template is passed the event object directly.
Tried the echo test and indeed it does not appear the custom template file is loading. So… what next?
and
I take it back – it is loading (I was checking the page under the wrong account).
What was the difference between the two account? One had no registrations and the other did?
So, because I’m not sure how this is actually working at all I can’t be sure on a fix, but in content-espresso_my_events-simple_list_table.template.php
Move if ( $event->get_active_status() == 'DTE' ) { return; }
Just below this line: $event = $registration->event();
You have the event there and it’ll check for the event status.
That should check the event and if all the datetimes have expired, skip it.
Unfortunately, I can’t see anything without an account that has registrations on an event (preferably an old event and a new event) and access to the template files to confirm they are loading (with the above it really doesn’t appear as though they are).
However, we don’t add/remove code through the built-in editors and would need FTP access to view what is going on, if you want me to take a look I’m happy to do so but you’ll need to provide all of the requested details on this form:
So I spent some time looking over your template files and as you mentioned, they are correctly loading from your child theme.
In content-espresso_my_events-simple_list_table.template.php I’ve added this:
if ( $registration->event()->get_active_status() == 'DTE' ) { return; }
To the first line of the template and now ‘old’ events no longer display in the table.
In a previous reply we changed the template file (which did actually make a change, it removed the ‘start date’, ‘Location’ and ‘Actions’ columns for that events row as it was after the event name, I missed that earlier) to try and figure out what was happening, so I can’t why the previous code didn’t throw a fatal previously but it now works.
I did try adding if ( $event->get_active_status() == 'DTE' ) { return; } in place of the code in use now and it did throw a fatal error (as expected), because there was no event object at that point, notice the new code pulls the event directly from the registration.
In any case, the account you sent me now only displays a single event in the list or February 26 and the older event has been removed. Can you confirm this now works how you are expecting?
It is indeed now filtering expired events, but not “inactive” events. I didn’t even know inactive was a status. One of my event is “inactive” – but I know know what that means. I tried deleting the inactive event, but it’s locked (i.e. it has a padlock icon next to it in the trash folder). Since I suspect there’s a valid reason for having inactive events (even if I don’t understand what that means), what code should I add to also filter those?
The support post ‘Hide Expired Events Redux’ is closed to new replies.
Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.
Support forum for Event Espresso 3 and Event Espresso 4.