Home › Forums › Calendar Products › Events Calendar PRO › Exclude past events from search results
- This topic has 9 replies, 3 voices, and was last updated 9 years, 10 months ago by
Josh.
-
AuthorPosts
-
May 31, 2016 at 12:09 pm #1120839
Meredith
ParticipantI’ve googled this and not found answers, though it seems to be a pretty standard request. I’ve also tried implementing solutions, none of which have worked. Past events still always show in my search results.
Seems that this should work, but it has no effect:
add_action( 'pre_get_posts', 'edcny_pre_get_posts' ); function edcny_pre_get_posts($query) { if (!is_admin() && $query->is_main_query()) { if ($query->is_search) { $meta_query = $query->get('meta_query'); $meta_query[] = array( 'key' => '_EventStartDate', 'value' => date('Y-m-d').' 00:00:00', 'compare' => '>=', 'type' => 'DATETIME' ); $query->set('meta_query', $meta_query); } } return $query; }I’ve also tried replace the $meta_query section with this:
$query->set('tribe_is_past', false);
and then with this:
$query->set('eventDisplay', 'upcoming');Those also don’t work. Where am I going wrong?
Thanks,
Aaron.June 1, 2016 at 7:08 am #1121128Josh
ParticipantHey Aaron,
Thanks for reaching out to us!
To clarify, is this intended to be for a generic search when having your events selected to be displayed alongside your main blog posts? Or is this intended to impact the search associated with the bar that displays above the main event views within our plugin?
Thanks!
June 1, 2016 at 8:50 am #1121177Meredith
ParticipantThanks for your quick reply, Josh.
This is intended for the main search of the site. Example:
http://cnyepiscopal.wpengine.com/?s=youthSee, for example, in those search results “Registration Deadline: 2016 Youth Pilgrimage to El Salvador” which has the event date of May 15.
Thanks!
Aaron.June 2, 2016 at 1:23 pm #1121828Josh
ParticipantHey Meredith,
Thanks for clarifying there.
Taking a quick look at your code above, have you tried with changing the second layer of the conditional there to be:
if( $query->is_search() )Thanks!
June 3, 2016 at 8:31 am #1122175Meredith
ParticipantJosh, that’s not the problem. The code as I’ve written it (above) already does execute on the search results page. It just doesn’t actually filter out past events.
June 6, 2016 at 11:01 am #1123108Meredith
ParticipantChecking in … Thanks.
June 7, 2016 at 7:08 am #1123328Josh
ParticipantHey Aaron,
I apologize for the delay here. I’ve been playing with the snippet and trying several different approaches but haven’t been able to get search results to limit only to future events either.
I’ll reach out to our team to see if anyone else has any input with a fresh set of eyes on it.
Thanks!
June 7, 2016 at 12:45 pm #1123538Meredith
ParticipantFound the problem; my pre_get_posts modification was being ignored because of interference from another plugin (SearchWP).
June 8, 2016 at 6:37 am #1123795Josh
ParticipantHey Aaron,
Awesome! I’m glad you were able to find a solution here.
I’ll go ahead and close this thread for now. If you have any further questions, please don’t hesitate to open a new one.
Thanks!
-
AuthorPosts
- The topic ‘Exclude past events from search results’ is closed to new replies.
