Exclude posts with certain meta data from search results

Question

I’m trying to exclude al posts with certain meta data from the search results but so far it’s not working.
Here’s the code I’m using:

function ZoekGeenLegeItems( $query ) {
    if( is_admin() || !$query->is_search() || $query->get( 'post_type' ) != 'item' )
        return $query;

    $query->set('meta_query', array(
      'relation' => 'OR',
        array(
            'key' => 'KEY_itm_leeg'
            ,'value' => '0'
        )
    ));
    return $query;
}
add_filter('pre_get_posts','ZoekGeenLegeItems');

Any ideas, anyone?

0
, , Jasper 5 years 2016-04-22T05:20:29-05:00 0 Answers 110 views 0

Leave an answer

Browse
Browse