How do I remove past events from showing up when doing searches?

Home Forums Calendar Products Events Calendar PRO How do I remove past events from showing up when doing searches?

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #1140054
    Cindy
    Participant

    Hey 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

    #1140261
    Josh
    Participant

    Hey 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!

    #1140907
    Cindy
    Participant

    Hi 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,
    Cindy

    #1141440
    Josh
    Participant

    Hey 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!

    #1142262
    Cindy
    Participant

    Hey 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

    #1142384
    Josh
    Participant

    Hey 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!

    #1143984
    Cindy
    Participant

    Hey 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

    #1144152
    Josh
    Participant

    Hey 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!

    #1144373
    Cindy
    Participant

    Hey 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=en

    This 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

    #1144611
    Josh
    Participant

    Hey 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!

    #1145759
    Cindy
    Participant

    This reply is private.

    #1146045
    Josh
    Participant

    This reply is private.

    #1149992
    Cindy
    Participant

    Hi Josh – Tried all of the above and nada helped. Sigh…..

    Other ideas?

    Thanks- Cindy

    #1150769
    Josh
    Participant

    Hey 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!

    #1159358
    Support Droid
    Keymaster

    Hey 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

Viewing 15 posts - 1 through 15 (of 15 total)
  • The topic ‘How do I remove past events from showing up when doing searches?’ is closed to new replies.