Support

Home Forums Event Espresso Premium Hiding expired events from view

Hiding expired events from view

Posted: July 19, 2023 at 4:15 am

Viewing 7 reply threads


Bauholz

July 19, 2023 at 4:15 am

Hello,

I use a custom template to display events. At the moment this is displaying all *elapsed* alongside current events, which we don’t want. We just want to show forthcoming events.

I’ve been looking for a way to hide these, and came across this code snippet that you’ve provided for other customers:
https://github.com/eventespresso/ee-code-snippet-library/blob/master/templates/de_ee_filter_events_out_with_expired_tickets.php

This appears to at least partially work for me. Expired events are hidden from view, but the site now shows multiple links for each event, based on how many ticket-types the event has (i.e. it shows three links to the same event if that event has three tickets-types assigned to it).

Would you be able to give a variation on the above snippet that will only show one link per event, regardless of how many tickets are assigned to it? Or could you suggest any other way of preventing elapsed events from showing across the site? (e.g. automatically unpublishing them?)

Thanks for any help you can offer


Tony

  • Support Staff

July 19, 2023 at 7:52 am

Hi there,

The above behaviour isn’t expected from that snippet and I suspect this is linked to your custom template:

I use a custom template to display events.

Which template for what output/endpoin?

Can you add the template to a PasteBin and post a link here for me to view the code?


Bauholz

July 20, 2023 at 9:26 am

This reply has been marked as private.


Tony

  • Support Staff

July 21, 2023 at 10:24 am

Hmm ok so yeah it’s from that ALM plugin.

Event Espresso events are a custom post type hybrid, the event posts are within wp_posts, but everything else uses custom tables all tied together using the post ID.

The easiest way I can think of doing this is using your second approach:

Alternatively, if there’s a way to generate a comma separated list of post IDs of non-elapsed events, I could use that to only show those posts.

$not_expired_event_ids = EEM_Event::instance()->get_all_not_expired_event_ids();

Thats going to return and array of Event ID’s for the above, does that work for you?


Bauholz

July 24, 2023 at 5:25 am

Hi Tony, and thanks for the help – I really appreciate it.

So I got the comma-separated list of ID’s working with the plugin shortcode… BUT… for some reason it still displays multiple entries for each event.

I’ve updated the pastebin link with the code I’ve just added to the template. I’ll paste this in a private reply below.

There’s a definite correlation between the amount of duplicate entries displayed, and the different ticket types for each event (i.e. an event with three ticket types available is shown three times)

Is there any way of taking the number of ticket types out of the equation?

Thanks again for any help you’re able to offer.


Bauholz

July 24, 2023 at 5:25 am

This reply has been marked as private.


Bauholz

July 24, 2023 at 5:53 am

Sorry! A quick update to the above…

I just realised that I had neglected to remove the original code snippet (from my first post) from functions.php.

After I removed that, the comma-separated-list fix appears to work…! 🤞

Thanks again for your help with this – it’s much appreciated.


Tony

  • Support Staff

July 25, 2023 at 5:40 am

Awesome, I’m glad yo found a solution 🙂

Any further questions just let us know.

Viewing 7 reply threads

The support post ‘Hiding expired events from view’ 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