• 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)
  • Thread Starter henriemedia

    (@henriemedia)

    I seem to have gotten this working, but there is one small issue. If you use this code, only posts that are events or have the meta_key “_EventStartDate” are returned in the results. How do I get this to only apply to posts with post_type=”sp_events” instead of all posts?

    Thread Starter henriemedia

    (@henriemedia)

    I seem to have gotten this working, but there is one small issue. If you use this code, only posts that are events or have the meta_key “_EventStartDate” are returned in the results. How do I get this to only apply to posts with post_type=”sp_events” instead of all posts?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom search query using meta data not working’ is closed to new replies.