Support

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

How to hide past events on the My Events shortcode

Posted: May 2, 2018 at 9:36 am


SupercarDriver

May 2, 2018 at 9:36 am

Currently, past events are showing along with upcoming events. we want to hide past events or separate from the upcoming list. Also, the entire list seems to be in a random order, it could be doing it from ID of the event rather than by date… any ideas how to sort by date?
Also if I wanted to customise the entire my events section to get away from the table and style it myself, which template would that be?


Tony

  • Support Staff

May 2, 2018 at 11:22 am

Hi there,

To remove expired events you can add the code mentioned here:

https://eventespresso.com/topic/any-way-to-hide-expired-events-in-the-espresso_my_events-shortcode/

Another user recently posted the same question and posted an example of the code here:

https://eventespresso.com/topic/hiding-expired-events-on-user-profile-page/#post-268317

However, the above will change if you want to customize the view, so:

Also if I wanted to customise the entire my events section to get away from the table and style it myself, which template would that be?

All of the template files used for the my events section are from:

\eea-user-intergration\templates\

The exact template depends on what you want to edit, but by the sounds of it your completely changing the output, which will effect all templates, starting from:

\eea-user-intergration\templates\loop-espresso_my_events-event_section.template.php

Note that EE will check for any copies of the current templates in your themes root directory, so you can override the templates by copying them there.


SupercarDriver

May 8, 2018 at 6:46 am

Hi, thanks for the reply,

When I went to edit the file it was already there yet members cannot see those changes applied (ie. they still see old events) I have cleared server cache and browser cache so works for me but can’t get 700 users to clear their own cache? any advice?

there was also another piece of code in there:

if ( $event->get_active_status() == 'DTI' ) { return; }

I have removed that and replaced so the start of the file now looks like this:

<?php
if ( $event->get_active_status() == 'DTE' ) { return; } // removes expired events
/**
 * Template for the "event_section" content template for the [ESPRESSO_MY_EVENTS] shortcode
 * Available template args:
 *
 * @type    EE_Event $event              event object
 * @type    string   $your_tickets_title title for the ticket.
 * @type    int      $att_id             The id of the EE_Attendee related to the displayed data.
 */

$registrations = $event->get_many_related('Registration', array(array('ATT_ID' => $att_id)));
?>


SupercarDriver

May 8, 2018 at 8:20 am

Also, all the events aren’t appearing in date order is there a way to force that as the date header has been removed on our new version…


Josh

  • Support Staff

May 9, 2018 at 12:02 pm

What may be happening is you’re editing the wrong template. If the shortcode is
[ESPRESSO_MY_EVENTS template=event_section]
then you’re editing the correct template.
If the shortcode is
[ESPRESSO_MY_EVENTS template=simple_list_table]
then you’ll need to make the edits to the
content-espresso_my_events-simple_list_table.template.php template file. It’s also important that the custom template file is in the correct location. The correct location is in the top level of your active WordPress theme.

With regards to the order, the registrations are listed by the date of registration. So the most recent registrations will be listed last.


SupercarDriver

May 9, 2018 at 2:27 pm

Hi, using:
[ESPRESSO_MY_EVENTS]
Would that make a difference? Every other change I have made to the template file is working…


Josh

  • Support Staff

May 9, 2018 at 3:17 pm

[ESPRESSO_MY_EVENTS template=event_section] is equivalent to [ESPRESSO_MY_EVENTS].

There are ways to have an expired event with a different status though, so this might work better for you:

if ( $event->get_active_status() != 'DTU' ) { return; }


SupercarDriver

May 14, 2018 at 8:03 am

Hi, that’s worked a treat, thanks, with the order of the events, is there a way to have them in date order, rather than ID?


Josh

  • Support Staff

May 14, 2018 at 8:41 am

They are in date order, showing most recent registrations last.


SupercarDriver

May 14, 2018 at 8:46 am

Hi yes, sorry, meant the event date order. So they appear in the order they happen in, not when registered.


Josh

  • Support Staff

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);
});
?>


SupercarDriver

May 15, 2018 at 7:39 am

Hi, After adding this on I got the following:

Fatal error: Uncaught Error: Call to a member function get() on boolean in /home/adamt364/public_html/membersfiles/wp-content/themes/blankslate/loop-espresso_my_events-event_section.template.php:47 Stack trace: #0 /home/adamt364/public_html/membersfiles/wp-content/plugins/event-espresso-core-reg/core/helpers/EEH_Template.helper.php(384): include() #1 /home/adamt364/public_html/membersfiles/wp-content/plugins/event-espresso-core-reg/core/helpers/EEH_Template.helper.php(296): EEH_Template::display_template('/home/adamt364/...', Array, true) #2 /home/adamt364/public_html/membersfiles/wp-content/plugins/eea-wp-user-integration/domain/entities/shortcodes/EspressoMyEvents.php(270): EEH_Template::locate_template('loop-espresso_m...', Array) #3 /home/adamt364/public_html/membersfiles/wp-content/plugins/eea-wp-user-integration/domain/entities/shortcodes/EspressoMyEvents.php(194): EventEspresso\WpUser\domain\entities\shortcodes\EspressoMyEvents->loadTemplate(Array) #4 /home/adamt364/public_html/membersfiles/wp-content/plugins/event in /home/adamt364/public_html/membersfiles/wp-content/themes/blankslate/loop-espresso_my_events-event_section.template.php on line 47

Which is:

$start = $datetime->get('DTT_EVT_start');


Josh

  • Support Staff

May 15, 2018 at 9:18 am

I forget that you were removing past events later. You can do this instead:

<?php 
foreach ($objects as $object) :
    $object->start = '';
    if (! $object instanceof EE_Event) {
        continue;
    }
    $datetimes = array();
    $datetime = EEM_Datetime::instance()->get_primary_datetime_for_event( 
        $object->ID(), 
        true, 
        false
    );
    if(! $datetime instanceof EE_Datetime) {
        continue;
    }
    $object->start = $datetime->get_raw('DTT_EVT_start');
endforeach;
usort($objects, function($a, $b) {
    return strcmp($a->start, $b->start);
}); 
?>

The support post ‘How to hide past events on the My Events shortcode’ 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.

Event Espresso