Support

Home Forums Event Espresso Premium Remove expired events from archive page for espresso_event_categories

Remove expired events from archive page for espresso_event_categories

Posted: January 24, 2022 at 10:04 pm

Viewing 7 reply threads


pathwise

January 24, 2022 at 10:04 pm

Currently I have setup a query modifier using the WordPress hook

pre_get_posts

where I have added the ability to sort the posts on the archive page by their event espresso start date.

function eventespresso_query_archive_order( $query ) {
if ( ! is_admin() && ( is_tax('espresso_event_categories') ) ) {
$query->set( 'orderby', 'Datetime.DTT_EVT_start');
$query->set( 'order', 'ASC');
}
};
add_action( 'pre_get_posts', 'eventespresso_query_archive_order');

Now I would like to modify this function to also remove events that have expired from displaying on the archive page for the taxonomy

espresso_event_categories

Any thoughts on how to do this?


Tony

  • Support Staff

January 25, 2022 at 4:37 am

Hi there,

Can you link me to the output you are referring to, please?


pathwise

January 26, 2022 at 7:55 pm

@Tony You can see it here https://nrtraininggroup.com/event-category/electro-cert/

Currently we have removed expired events but we would not like to remove expired events from our backend, instead adjust the query for posts to remove expired events.


Tony

  • Support Staff

January 27, 2022 at 9:41 am

Are you aware we have a section within Event Espresso to enable/disable expired events on event lists?

Event Espresso -> Events -> Template -> Event list pages.

Set ‘Display Expired Events’ to No and save.

That change affects all frontend auto-generated event lists (and the [ESPRESSO_EVENTS] shortcode)

With regards to the code you are using above, the posts should already be sorted by Event Start ASC, are you sure that code is running?

The reason I ask is the dot notation you are using relates to our model system and I don’t think it will work directly with WP_Query, are you sure that snippet changes the output at all?


pathwise

January 27, 2022 at 12:27 pm

Yes, that is checked.
Unfortunately it does not have any affect on the output generated on that Taxonomy Archive page.

Yes the code does have an effect, I can share with you two screenshots, one with the code and one without the code.

With the code in place: https://ibb.co/S6rws19

Without the code in place: https://ibb.co/rxTj2n0


Tony

  • Support Staff

January 28, 2022 at 3:26 am

Unfortunately it does not have any affect on the output generated on that Taxonomy Archive page.

Hmm, sounds like something else is happening here then as it should change that output.

Yes the code does have an effect, I can share with you two screenshots, one with the code and one without the code.

Yeah, again that’s odd.

Are you using a custom template in your theme for the taxonomy archive?

Can you send me a copy of the theme to have a look locally?


pathwise

January 28, 2022 at 10:31 am

This reply has been marked as private.


Tony

  • Support Staff

January 31, 2022 at 5:37 am

Hmm, strange.

The output on the taxonomy archive for me locally is very different from what you have.

Schoolboy error on my part for the code you are using above, it will work on EE events as EE hooks in and handles the joins already for output queries so adding the above will indeed order them as expected.

However, I’m not sure why you are getting different results here, the query seems custom as the above is the default and the options set in the template section I mentioned should affect the results (and they do locally for me).

Are you hooking into the output with a custom plugin at all?

We do have some examples of removing expired events using pre_get_posts:

https://github.com/eventespresso/ee-code-snippet-library/blob/master/templates/de_ee_filter_events_out_with_expired_tickets.php

https://gist.github.com/joshfeck/a170dc264548513f4b7ab77074ab9e61
(That’s using search but same idea)

But I’m confused as to why you’re getting a different output than expected here and the above may not work with it.

Viewing 7 reply threads

The support post ‘Remove expired events from archive page for espresso_event_categories’ 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