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 to filter post listing (in WP dashboard posts listing) using a custom field (search functionality)?
- How do I improve this admin query snippet to avoid generating duplicate results on non-meta searches?
- ORDER BY custom field value
- How can I change the admin search posts fields?
- 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?
- Admin Area Custom Type Search By Meta Fields Without Title & Content
- SELECT max(meta_value) FROM wp_postmeta WHERE meta_key=’price’… stops working when value is over 999
- Filter post listing by meta value which is a date
- Matching Serialized Arrays with meta_query
- Meta Query with AND & OR?
- Custom search: by post data and post metadata?
- Need small coding with Custom Fields Search
- Adding Custom Field to Taxonomy Input :Panel
- Auto sort the wp-admin post list by a meta key
- Show Custom Comment Fields when editing in admin
- Search ONLY by meta key / meta values
- How to activate “custom fields” section in WP3
- How to prevent custom fields from being cleared during a bulk edit?
- Filter results with custom field values and dropdown
- Add custom field (value) to search result (without plugin)
- Custom text-only header
- Trying to perform complex custom field query with order by set to field value
- searching in custom meta field
- Custom bulk action for media gallery items
- How To Create a Metabox of HTML Content with Instructions For Editors When Editing a Post or Page?
- Backend search; include CPT meta?
- How to load php file for specific page in admin?
- Compare meta_query decimals not working right
- Ordering posts by anniversary using only day and month
- Calling Specific Pages with wp query Part II
- Loop through two different sets of custom fields
- Exclude custom post type from search by custom field value?
- How to show custom field’s value under post/page title in wp-admin
- 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
- How can I query on the year part of a complete date in a custom field?
- How can I combine meta_query queries?
- 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
- Can you ungroup Custom Fields?
- meta_value_num sort glitch
- 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
- Which is best in the following scenario : post_meta vs custom table vs parent/child posts
- WP_Meta_Query causing long-running MySQL queries
- Including Database Generated Pages in Site Search [closed]
- Add field to ‘Add User’ admin page
- Sorting posts by custom fields in meta_query
- meta_query for a string inside a meta field containing a comma-separated list
- Order by custom field value not working for acf date field
- Adding Custom Fields to Search
- Add More Fields to Users Pages (Admin Panel)
- sort search results by custom fields using dropdown
- Using a checklist to search against metadata
- Complex WP_User_Query call fails on production server
- How do I use wp_query for WordPress search?
- Meta query with timestamp using WP_query
- Custom Fields Not in Search Results
- Orderby custom field meta value ASC and then by date DESC
- 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
- WP 3.1 meta_query for multiple custom field values
- 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
- Client PDF Upload (Catalogue) – Automatically update link to PDF
- Advanced search for meta fields
- Get posts with same meta value as current post
- Merge Multiple Custom Fields into one New Custom Field for Searching
- Button inside Custom Meta Box triggering the Update Button
- Alter main archive, to show posts with meta as last
- How to load an assets based on custom field value?
- Meta Query returns wrong number of posts
- 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
- Change order of posts
- Meta Query And/Or
- Use meta_query to get title of associated post
- Meta query with multiple custom fields for archives page ordering problem