• Resolved clane_workforce

    (@clane_workforce)


    Hello,

    I am trying to add code to my child theme functions.php to exclude past events from the standard WordPress Search. I have the code blow from another thread, but it is not working. Any help is appreciated, as I see this is an issue that many are trying to resolve.

    add_action( 'pre_get_posts', function( $query ) {
    
    	if ( ! is_admin() && $query->is_main_query() && $query->is_search() ) {
    
    	  	$today = date('Y-m-d');
    
    		$meta_query = array(
    
    		'relation' => 'or',
    
    			array(
    
    			'key'=>'event_start_date',
    
    			'value'=>current_time( 'Y-m-d' ),
    
    			'compare'=>'>=',
    
    			'type' => 'DATE'
    
    			),
    
    			array(
    
    					'key'     => 'event_start_date',
    
    					'compare' => 'NOT EXISTS',
    
    				),
    
    		);
    
    		$query->set('meta_query',$meta_query);
    
    	}
    
    });

    https://www.ads-software.com/plugins/events-manager/

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Exclude Past Events from WordPress Serach’ is closed to new replies.