pre_get_posts
is an action, not a filter. Change this:
add_filter('pre_get_posts','searchfilter');
to this:
add_action('pre_get_posts','searchfilter');
You also don’t need to return $query
.
See documentation for pre_get_posts: http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts
Related Posts:
- Using meta query (‘meta_query’) with a search query (‘s’)
- Add custom fields to search
- Is there a way to do multiple ordering on a multiple meta_query?
- WordPress Search Custom Meta Field Only
- How do I have WP_Query match posts based on search parameter OR meta fields? (rather than search parameters AND meta fields)?
- filter custom field values $min $max
- Need to search a custom field (ingredients, one long string per post), but want it to allow phrases/non-exact matches
- Search & column order by meta value in admin
- Create custom query for search?
- Add filter menu to admin list of posts (of custom type) to filter posts by custom field values
- How do I improve this admin query snippet to avoid generating duplicate results on non-meta searches?
- ORDER BY custom field value
- Using TinyMce with textareas in meta boxes on custom post types
- Can I query custom meta data through WP_Query
- Including custom fields in search?
- Custom search: by post data and post metadata?
- Search ONLY by meta key / meta values
- Filter results with custom field values and dropdown
- Trying to perform complex custom field query with order by set to field value
- searching in custom meta field
- How To Create a Metabox of HTML Content with Instructions For Editors When Editing a Post or Page?
- Calling Specific Pages with wp query Part II
- Slow meta query with multi meta keys
- Why does this Quick Edit checkbox save the value only when unchecked?
- Using OR in WP_Query negates the “NOT EXISTS” compare
- Displaying posts with only upcoming dates according their custom field date value
- Difference between ‘LIKE’ and ‘IN’ in meta queries
- Sorting posts by multiple values, combined
- WP_Query display next custom post from today’s date
- Extend ‘The Events Calendar’ search to include custom fields [closed]
- Include woocommerce custom field value in front-end search result
- WP_Meta_Query causing long-running MySQL queries
- Including Database Generated Pages in Site Search [closed]
- Add field to ‘Add User’ admin page
- Adding Custom Fields to Search
- Add More Fields to Users Pages (Admin Panel)
- Using a checklist to search against metadata
- Admin meta Image Path
- filtering custom post types via meta data drop down
- How to add a new meta key and assign timestamp to posts
- Get content from pages with same meta_key from Database
- Custom Fields – Taller editing area
- Speed up / Optimize Admin Edit Post Page on Large Websites (50-150k posts, 50 custom fields per post)
- Custom Fields box in the post editor: Replace textareas with input elements
- Advanced search by two criteria – sort by location and date (ascending or descending)
- Custom Meta Box (SELECT) Not Saving
- Extend product search with meta in WooCommerce
- Advanced search for meta fields
- Get posts with same meta value as current post
- Button inside Custom Meta Box triggering the Update Button
- Alter main archive, to show posts with meta as last
- Meta Query returns wrong number of posts
- How to populate custom field dropdown box based on prior selection?
- filter search custom field query
- I need a “Choose from existing content” popin
- Restrict WordPress Search to Custom Field
- How can you include custom post meta in search without calling each key?
- Get Data From wp_sitemeta for Multisite network
- get posts where a custom field contains a text
- Avoiding ACF get_field and returning to core WordPress function
- ORDER BY custom field value out of where clause
- Query post by date (stored custom field meta as yyyymmdd) and differentiate across 12 months
- ACF: How to get users with a ACF flexible content subfield with a specific value AND layout?
- WordPress colorpicker save both hex and RGB
- Meta_query ‘compare’ => ‘LIKE’ not working?
- Diamond question mark in text after migrating content
- Include one custom field in search results
- TinyMCE custom button retrieve value from custom field
- 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?
- Jquery on custom-field backend
- Best way to sort estates and query them (for rent? yes/no. contains office space? yes/no)?
- How to show content of custom fields in search results?
- Searching with Multiple (Parallel) Criteria on Custom Fields?
- Make separate text boxes for separate WordPress Custom Fields
- Making WP_Query limit results by date before today where date is a meta_query
- WP meta_query args not working in function
- Filtering posts by ACF meta query
- Very large list of options for BuddyPress profile fields
- Why does my numeric meta query work only on one meta key and not the other?
- meta_query to check all custom fields
- WordPress admin area: select box with 12.000+ options
- Sort columns in the ‘Pages’ dashboard overview
- Search fails when using the radio buttons
- Link fields in User Admin list
- Save custom post data outside of default post form
- Admin – Search Events by a custom field
- Sort custom fields in admin by last field added
- Query postmeta values, and return multiple post_titles for common meta value
- Custom Field select list is truncated
- Query Posts Via WordPress URL
- Meta_query not filtering posts
- Decouple page name from page title
- Dynamic background image used in css after selector
- Add custom fields to specific menus
- How to make donation button dynamic on chariti theme [closed]
- WP Query Args – search by meta_key or title
- Search for meta_query does not return any result if combined with title