First, the pre_get_posts
hook is an action and not a filter.
Then the meta_query
parameter should contain the relation
only if there is more than one inner meta_query array (codex).
Finally you do not need to return the $query
argument as it is passed by reference to your callback function.
Your code should look like this:
function ZoekGeenLegeItems( $query ) {
if( is_admin() || !$query->is_search() || $query->get( 'post_type' ) != 'item' )
return;
$query->set('meta_query', array(
array(
'key' => 'KEY_itm_leeg',
'value' => '0'
)
) );
}
add_action('pre_get_posts','ZoekGeenLegeItems');
Related Posts:
- WP User Query with search columns and meta query
- Combining Meta_Query key values for one array
- Do not allow to search certain words
- pre_get_posts and search query for admin
- Default WP search excluding specific characters, is it possible?
- Comparing between a negative and positive number
- Advanced Search by minimum/maximum values
- Searching by meta values showing inappropriate result
- WordPress, fetching users with an exact match in a string of comma separated values in user_meta
- Meta query: How do I return posts within a date period from a given month?
- meta_query issue with multiple numerics
- Custom Query Content Filtering
- Search by meta_query
- Form for search pages by meta datas
- WP search in metadata post
- How to exclude one post format from search result?
- Using meta query (‘meta_query’) with a search query (‘s’)
- How can I implement a location based (zip code) search in WordPress?
- How to highlight search terms without plugin
- Complex Search functionality. Advice needed
- How to use next_post_link and previous_post_link on single posts in search results
- Why is there a class=”screen-reader-text” on my search button?
- can’t limit search to only pages
- How to exclude post body from WP search
- Search outside of the “loop”
- Replace URL with Site Title in Search Results
- Force WP to use a certain search template
- Best way to Integrate Google Search?
- How to add additional search terms (e.g. synonyms) to the search?
- Combine internal search with Google custom search?
- Any reason why search result lists only one entry?
- Display just child pages of a certain page in search results
- How to make wordpress default search to woocommerce search
- pre_get_posts action: Search by post_title and post_content with different search phrase in the same query
- Why won’t is_search work inside functions.php?
- Search functionality – include date, category and author search
- WordPress Search matching hyphenated words
- How to stop WordPress Search form from searching only in current page?
- filter custom post type by meta key in dashboard
- How can I make a search form that can search taxonomies and posts?
- How can I include author (their archive page) in search results?
- How to search media library alt text and title fields
- how to create search and filter form generating “plus” symbols in url in between category names?
- Change Search url slug for each site in a multisite network
- Creating a Searchable PDF Archive of Publications
- Is there a way to add a custom text + link above search results for different searches?
- WordPress Filtering Custom Post Type by Metadata and Search Heirachy
- Display post titles that match string in post content
- Template issues getting ajax search results
- How can I implement Search feature for Membership site?
- filter search custom field query
- Search – Only search for post meta field
- Search Form Based On Tutorial Not Working
- how to show Author information in search results
- Sitelinks Search box schema confusion
- The Search FoRM Dilemma || The Search form Templating
- How do I remove duplicate users from two merged WP_User_Query objects?
- How can I add search box in single.php?
- Connecting Google Site Search with WordPress Taxonomies/Categories/Tags
- My default search is not working
- Only display post content in search results
- meta post search
- search page not found? (search.php or searchpage.php)
- Media Library / Backend: How can I search for text in the ALT Text field?
- Rewrite wp function
- How to fetch Email addres of an author via ID?
- How to Fix Form elements do not have associated labels in WordPress Search Form (without button)
- How to exclude specific post_type from default search?
- Search issue on special Character
- Modify main search form to search user too
- Removing &submit=Search from search parameters?
- customize search result in wordpress
- Highlight search words in excerpt
- $_GET value is losing it’s space
- Search For Custom Post Type and Custom Fields
- Searching on my blog is not working
- “Modular/reusable” content and search results
- Add Search Form to Dropdown menu
- Search doesn’t work with ‘relation’ => ‘OR’
- Add meta tag to search results
- Searchform for searching specific categories
- Selectbox and Searchform and Custom Search Page
- Hightlight search-terms with functions does remove or disable other filters?
- SQL: Search query to get attachments only of those parents which are published
- Change the text “search result for” on search result page
- Search redirects to index
- Putting Text in the Search Box. eg- “Search My Site” [closed]
- Want to creat a search for my wordpress theme [closed]
- Return 404 for /search/ queries – For Genesis
- Deprecating WordPress URL from Google, promoting custom domain [closed]
- Search with multiple selects that include tags
- Search results from a specific database table
- Using ‘meta_query’ with the ‘pre_get_posts()’ hook disables searching for post titles
- How do I create a search form that searches only within a custom post type?
- Two Querys in one Search – Category-Tag nightmare – HOW?
- Code in the excerpt of the search page
- WordPress REST API response – not returning results from custom taxonomy, only from title
- Members location sortable based on UK Postcode
- I had removed my phone number from my website footer, but months later it still appears once I look it up on google, how to remove it?
- search posts by POST ID