You need to implement a hook for pre_get_posts
filter, in which you can set what you need. Pay attention that you should change only search query, so you have to check if is_search()
method returns true. The hook should look like this:
add_filter( 'pre_get_posts', 'wpse8170_pre_get_posts' );
function wpse8170_pre_get_posts( WP_Query $query ) {
if ( $query->is_search() ) {
$query->set( 'post_type', array( 'resources' ) );
$query->set( 'meta_query', array(
array(
'key' => 'resource_usertype',
'value' => array('Public', 'Students', 'Alumni'),
'compare' => 'IN',
)
) );
}
return $query;
}
Related Posts:
- Using meta query (‘meta_query’) with a search query (‘s’)
- Including custom fields in search?
- Add custom fields to search
- Custom search: by post data and post metadata?
- Need small coding with Custom Fields Search
- Search ONLY by meta key / meta values
- Filter results with custom field values and dropdown
- Add custom field (value) to search result (without plugin)
- Is there a way to do multiple ordering on a multiple meta_query?
- searching in custom meta field
- WordPress Search Custom Meta Field Only
- Extend ‘The Events Calendar’ search to include custom fields [closed]
- Include woocommerce custom field value in front-end search result
- Including Database Generated Pages in Site Search [closed]
- Adding Custom Fields to Search
- sort search results by custom fields using dropdown
- Using a checklist to search against metadata
- How do I use wp_query for WordPress search?
- Custom Fields Not in Search Results
- How make a custom search on backend in WordPress without plugin?
- filtering custom post types via meta data drop down
- Advanced search by two criteria – sort by location and date (ascending or descending)
- How do I have WP_Query match posts based on search parameter OR meta fields? (rather than search parameters AND meta fields)?
- Advanced search for meta fields
- Merge Multiple Custom Fields into one New Custom Field for Searching
- How to populate custom field dropdown box based on prior selection?
- Search in Archive Pages by subcategory, tag, custom field and year
- Custom WP_Query for WordPress Search Results with meta_query
- filter custom field values $min $max
- Restrict WordPress Search to Custom Field
- How can you include custom post meta in search without calling each key?
- Include one custom field in search results
- Custom search SQL Query to add custom field in result
- Search Results Page – Displaying Custom Meta Fields
- Custom field Search with Relavanssi
- How to exclude custom fields from search queries?
- How to show content of custom fields in search results?
- Searching with Multiple (Parallel) Criteria on Custom Fields?
- Need to search a custom field (ingredients, one long string per post), but want it to allow phrases/non-exact matches
- Type character in name and make it invisble
- Search & column order by meta value in admin
- search based on custom field
- Very large list of options for BuddyPress profile fields
- searching by keywords in post’s metas or pagination links problem
- Search fails when using the radio buttons
- Admin – Search Events by a custom field
- Search one custom field?
- Create custom query for search?
- Query postmeta values, and return multiple post_titles for common meta value
- Query Custom Fields in Searchform
- Help sorting by Meta Key value
- Custom search with meta fields
- How to display search query as formatted text?
- Search for meta_query does not return any result if combined with title
- Add a Jquery Datepicker to custom field in post edit
- How can I avoid re-inventing the Custom Fields wheel in my Plugin’s Metabox?
- Does wordpress have something like content-type?
- Order Posts by Closest Numeric Values
- How to get and edit custom fields if in Quick Edit
- Create additional short URL with custom field and 301 redirect
- Create custom field on post draft or publish?
- Using OR in WP_Query negates the “NOT EXISTS” compare
- How to add a predefined custom field without using a plugin?
- PODS performance vs custom field
- How do you create dynamic customised sections in WordPress?
- How to enable Custom Fields that are disabled by theme?
- how can i stop custom fields that have apostrophes from breaking my code
- Should custom meta boxes be able to output shortcodes the same as WordPress’ native post editor?
- WPML & CFT: keeping custom field file to translation
- How to make condition, based on custom fields value?
- How do I Implement Atomic Update of Post Metadata?
- Custom fields value
- Want to make A CSS if meta key value is empty
- Outputing a metabox textarea and avoid line breaks inside li tags
- How to add a custom field to a post created programmatically?
- Custom post type missing custom fields
- Problem with saving large amount of data in postmeta/usermeta
- How to get posts with a metadata numeric key greater than X?
- “Matching” or “Linking” Two WordPress Pages: Custom Fields?
- Add custom attributes to a post
- Custom Taxonomy Search result page
- Meta_query ‘compare’ => ‘LIKE’ not working?
- Get text from user and display it on page
- If metabox has content display content
- Custom meta boxes not saving
- Listing the most popular 8 city (custom fields) as used in posts
- How to delete file uploaded by Plupload
- Display Meta Data with HTML?
- Taxonomy or Custom Field
- Order by custom date field
- Meta field bulk editing no longer working in WP 6.0 [closed]
- Custom Field: how to save array of multiple key-values in WordPress
- Delete user meta but only if found in array
- meta_query to check all custom fields
- Show Custom Taxonomy as Headline for related posts
- display Flexible Fields from options
- How to filter post using custom feild value in shortest and longest duration?
- Get custom field from page, in a post?
- Advenced custom fields auto fill problem
- How to add an ACF only for parent term?