Home › Forums › Calendar Products › Events Calendar PRO › How do I remove past events from showing up when doing searches?
- This topic has 15 replies, 4 voices, and was last updated 9 years, 8 months ago by
Cindy.
-
AuthorPosts
-
July 14, 2016 at 6:51 pm #1140054
Cindy
ParticipantHey Josh,
Sorry for delay in getting back to you. Thank-you for the link to the snippet. Can you please advise what file the php should go in? It is not mentioned.
Thanks!
Cindy
Please see original post: https://theeventscalendar.com/support/forums/topic/how-do-i-remove-past-events-from-showing-up-when-doing-searches/#post-1132395
July 15, 2016 at 7:04 am #1140261Josh
ParticipantHey Cindy,
Thanks for following up here!
You can add that snippet to your child theme’s functions.php. If you don’t have a child theme created for your primary theme and/or are uncomfortable with adding code to your site. You could add the snippet using a plugin such as https://wordpress.org/plugins/code-snippets/.
Let me know if this helps.
Thanks!
July 17, 2016 at 5:48 pm #1140907Cindy
ParticipantHi Josh,
I copied the code into the code-snippet plugin and past events are still showing. This is what I used:
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;
}For example:
http://footstepsofwisdom.com/?s=Caroline+myss&lang=en
The bottom two results are past events. I am trying to hide these. I think it odd that Event Calendar does not have an option show or not show past events.
Thanks again,
CindyJuly 19, 2016 at 7:09 am #1141440Josh
ParticipantHey Cindy,
Thanks for following up with us here.
I tested the snippet with my local install and verified that it was preventing the passed events from showing in the listings. Try copying from the following snippet and see if that helps to change things. If not, would you mind creating a snippet with your full functions file and sending a link over to that for verification?
https://gist.github.com/BeardedGinger/318b8b8752d345b0b0390fa6e80e28a4
Thanks!
July 20, 2016 at 8:35 pm #1142262Cindy
ParticipantHey Josh,
Thank-you so much for your reply.
I just tried the snippet you sent. It breaks Relevansi Search plugin that I need since Avada does not have a good search option.
Is there anything else you can suggest for now?
Also, can request the development team to add the ability to hide old events from plugin settings?
Thanks,
Cindy
July 21, 2016 at 7:36 am #1142384Josh
ParticipantHey Cindy,
Thanks for following up here.
Something you could try would be to change the priority of the hook when using the snippet. Maybe try, “add_action( ‘pre_get_posts’, ‘edcny_pre_get_posts’, 100 );” to increase the priority and possibly let this run after anything that Relevansi is doing for the search.
The feature is definitely a good suggestion! We would love to have you add the idea to our UserVoice page to allow others to vote on the feature as well.
Thanks!
July 25, 2016 at 8:51 pm #1143984Cindy
ParticipantHey Josh,
Thank-you for the above suggestion, but it didn’t work. 🙁
I just saw this in an earlier email, but I don’t know what you mean. I’m not very savvy with this stuff. Can you explain more on the line below? :
If not, would you mind creating a snippet with your full functions file and sending a link over to that for verification?Thanks!
Cindy
July 26, 2016 at 7:25 am #1144152Josh
ParticipantHey Cindy,
Sorry the other suggestion wasn’t helpful in addressing that conflict with the other search plugin.
That suggestion was to copy the contents of you functions.php file to a site such as gist.github.com so I could see whether there was an issue with where it may have been placed within the code. However, since you were able to narrow down to a conflict with the other search plugin, that suggestion wouldn’t be as helpful here.
Thanks!
July 26, 2016 at 1:36 pm #1144373Cindy
ParticipantHey Josh,
The first snippet you suggested broke Relevancy but it did not remove my old stuff. Then I added add_action( ‘pre_get_posts’, ‘edcny_pre_get_posts’, 100 ) . This kept Relevancy from breaking but did not help with the filtering of old events.
I have deactivated Relevancy and you can still see old events.
Please see this link. Go to page 2.
http://footstepsofwisdom.com/page/2/?s=Caroline+myss&lang=enThis is everything I have in the Snippet:
add_action( ‘pre_get_posts’, ‘edcny_pre_get_posts’, 100
add_filter(‘tribe_events_pre_get_posts’, ‘filter_tribe_all_occurences’, 100);
function filter_tribe_all_occurences ($wp_query) {
if ( !is_admin() ) {
$new_meta = array();
$today = new DateTime();// Join with existing meta_query
if(is_array($wp_query->meta_query))
$new_meta = $wp_query->meta_query;// Add new meta_query, select events ending from now forward
$new_meta[] = array(
‘key’ => ‘_EventEndDate’,
‘type’ => ‘DATETIME’,
‘compare’ => ‘>=’,
‘value’ => $today->format(‘Y-m-d H:i:s’)
);$wp_query->set( ‘meta_query’, $new_meta );
}return $wp_query;
}Thank-you for explaining what you meant. I will have the person that helps me get that copied and sent to you.
Thanks,
Cindy
July 27, 2016 at 7:50 am #1144611Josh
ParticipantHey Cindy,
Thanks for following up here and clarifying! I understand where you’re at now. Getting the copy of the functions file will definitely help in seeing what may be going on here with trying to set that snippet.
Thanks!
July 29, 2016 at 5:54 pm #1145759Cindy
ParticipantThis reply is private.
August 1, 2016 at 5:30 am #1146045Josh
ParticipantThis reply is private.
August 10, 2016 at 8:18 am #1149992Cindy
ParticipantHi Josh – Tried all of the above and nada helped. Sigh…..
Other ideas?
Thanks- Cindy
August 11, 2016 at 5:15 pm #1150769Josh
ParticipantHey Cindy,
I’m sorry the other steps didn’t help you out here.
Another option to test would be to switch to a default theme and try the snippet in that theme’s functions.php file to try to rule out any issues with the implementation of the snippet.
Thanks!
September 2, 2016 at 9:35 am #1159358Support Droid
KeymasterHey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.
Thanks so much!
The Events Calendar Support Team -
AuthorPosts
- The topic ‘How do I remove past events from showing up when doing searches?’ is closed to new replies.
