• Resolved Jennyfer37

    (@jennyfer37)


    Hi,

    Can anyone help? My site search brings up past events and I don’t know how to exclude them. Either that or I’ll have to turn off search for events altogether which I don’t really want to do. Anyone had the same problem and resolved it?

    Thanks
    Jen

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support angelo_nwl

    (@angelo_nwl)

    hi,

    you can try this snippet

    
    function SearchFilter($query) {
        if ($query->is_search) {
            $query->set('meta_key','_event_start_date');
            $query->set('meta_query', array(
                          array('key'=>'_event_start_date'),
                          array('key' => '_event_end_date', 'value' => date('Y-m-d'), 'compare' => '>=', 'type' => 'DATE')
                        ));
        }
        return $query;
    }
    add_filter('pre_get_posts','SearchFilter');
    

    As for where to paste this : https://wp-events-plugin.com/tutorials/how-to-safely-add-php-code-to-wordpress/

    Thread Starter Jennyfer37

    (@jennyfer37)

    Hi,

    Thank for the code – and so sorry it’s taken me so long to respond!

    I’ve added the code to the function php file of my child theme – now my site search returns no results at all though (events or otherwise). Any thoughts?

    Thanks
    Jenny

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Site Search and Past Events’ is closed to new replies.