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?

--------------------------------------------------

>>> Share a link to this question, just copy and paste the code bellow on your web page <<<

<a href="https://www.wptricks.com/question/exclude-posts-with-certain-meta-data-from-search-results/">

Exclude posts with certain meta data from search results</a>
0
, , Jasper 4 years 0 Answers 39 views 0

Leave an answer