Custom search query using meta data not working
-
I am trying to modify the search results to only include future events that I have added via the meta data but I can’t seem to get this working. Any help would be appreciated! Thank you.
function exclude_old_events( $query ) { if ( $query->is_search ) { $yesterday_before_midnight = date(“Y-m-d”, mktime(0, 0, 0, date(“m”),date(“d”)-1,date(“Y”))).’ 23:59:59′; $meta = array( array( ‘key’ => ‘_EventStartDate’, ‘value’ => $yesterday_before_midnight, ‘compare’ => ‘>’ )); $query->set( ‘meta_query’, $meta ); }} add_action( ‘pre_get_posts’, ‘exclude_old_events’ );
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Custom search query using meta data not working’ is closed to new replies.