Support

Home Forums Event Espresso Premium Custom WP Query for events is displaying expired events.

Custom WP Query for events is displaying expired events.

Posted: August 29, 2017 at 11:13 am

Viewing 1 reply thread


jrengo

August 29, 2017 at 11:13 am

Hi, I have this query on my site used to display events related by a taxonomy to the current event you are on:


$post_slug=$post->post_name;
$this_post = $post->ID;
$topicTerms = get_the_terms(get_the_ID(), 'event_topic' );
if ($topicTerms){
$topicTerms_list = wp_list_pluck($topicTerms, 'slug' );
}
$args = array(
'post_type' => 'espresso_events',
'posts_per_page' => 3,
'orderby' => 'rand',
'post__not_in' => array($this_post),
'public' => true,
'tax_query' => array(
array(
'taxonomy' => 'event_topic',
'field' => 'slug',
'terms' => $topicTerms_list,
)
)
);

It works fine, but it still displays events that are expired. I’ve also using the EE Query which then doesn’t display the expired events, but then I can’t use ‘post__not_in’ to not display the current post. Any thoughts?

Thank you.


Josh

  • Support Staff

August 29, 2017 at 11:25 am

I don’t see anywhere in your code that tells the query to exclude expired events. Here’s a link to some example code that shows how to use the WordPress posts_join and posts_where filter hooks to exclude expired events:

https://gist.github.com/joshfeck/ae206b13b751743b08137e72dc55151e

Viewing 1 reply thread

The support post ‘Custom WP Query for events is displaying expired events.’ 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