I came across the same problem.
In my opinion, this should be the default search behavior in WP.
The solution is to filter the array of parsed query variables.
See the documentation here.
Add this to the functions.php
file in your theme directory.
add_filter('request', function ($query_vars) {
if (!is_admin() && !empty($query_vars['s'])) {
$query_vars['s'] = trim($query_vars['s']);
}
return $query_vars;
});
Related Posts:
- How to modify posts_where filter only for the search query
- Search with filters and title
- Search pre_get_posts filter which can handle multiple post types and categories?
- Filter keywords from search query
- Ignore dots when searching in the media library?
- Search results sorted by post types
- Adding id and class to the search input in WordPress search form
- How to apply filter at search of woocommerce products?
- How to edit dashboard search posts button texts for my CPT?
- Filter custom post type using multiple taxonomy dropdowns
- Admin Backend – Search Pages only by title
- Comment search plugin
- Create Search Form to Filter Through Terms
- Map plugin with proximity search compatible with Buddypress
- conditional search
- Filter with two id of the same value CPT UI(taxanomies)
- How to set a filter search for categories of blog posts in wordpress
- Customising the default wordpress search functionality
- Right filter for rewriting page statuscode
- Search with filters
- Modify WordPress search behaviour in backend?
- Re-order search results with posts_orderby filter and post meta value
- meta box loop problem with a search filter
- Remove the post_content search from WHERE clause (and CONCAT sql function)
- Custom search fields and AJAX support
- How we make the filter for fornt end user
- Filter and Search
- Taxonomy search filters
- Filter posts by multiple checkbox categories
- How do you disable the verification process of user email changes?
- Search and Filter Using Custom Post Type, Custom Taxonomy, and Advanced Custom Fields
- what is __return_false in filters
- Passing Additional Parameters to add_filter Callable
- Custom theme hooks / filters – passing arguments
- Change upload directory on custom plugin page
- What params are available with the_content filter?
- How to hook wp_list_pages?
- Don’t replace “|” with Empty String (“”) when generating slugs from title
- apply_filters(‘the_content’, $content) alternative
- How to use the_excerpt in a filter hook?
- Changing document title only on a custom page template
- Shortcodes not resolved in AJAX call response
- Possible to filter the posts or categories that XML-RPC users see in their mobile application?
- wp_link_pages output appears twice
- Add filter to wp_dropdown_pages() or wp_dropdown_categories() – no select container?
- Hook different functions to the same filter conditionally OR Pass additional arguments to existing filter?
- How do I pass the value from a foreach loop to an add_filter function? [closed]
- Pass parameter to the upload_dir filter
- Filter or Hook to catch pre-rendering of post content
- check to see if hook is available
- Use add_filter on concatenated string variable
- Filter users by custom colum not meta key
- How to allow users to view pending posts of a specific custom post type?
- Remove filter callback: method in class
- How can I exclude tags from category_rss function?
- How to filter meta_values using REST API
- How do I use remove_action on an add_action that uses an array?
- Change the default 10-day expiration for the password protected pages cookie
- Add content as soon starts
- Access get_the_title() from ‘excerpt_length’ filter
- Wrong post_status notice after wp_insert_post_data
- Search filter triggered & sort by custom post type
- Admin search post meta
- How to display the content HTML of a page without displaying the gallery code as well
- Is it possible to apply_filter on a wp_ajax_ action?
- Apply filters with multiple filters
- Remove Comment Author Link only for subscribers
- Prevent reset password specific user role
- add_filter the_content doesn’t work
- Redirect to woocommerce checkout after adding to cart – item already in cart
- `authenticate` filter never gets called
- How to disable a wp filter in a certain admin panel page
- Is there a filter to programmatically change the HTML tab switching output of the page editor?
- post_orderby filter breaks function
- Disable Remember Me in Login Form
- How do I add a line break to a string that is output by PHP?
- Counting a WP_Post Object value in an arary, using a filter?
- style_loader_tag not changing stylesheet to preload
- List all categories that have results in a query
- Distinguish between page and post in function
- Display posts from today and future in Elementor ‘posts widget’
- Changing title using filter not working with argument
- Archive Widget – Count only parent posts
- How to filter page title for certain page?
- Displaying posts on a page that have been assigned a value in a database
- Replace Text with hyperlinks
- adding an action inside if condition not working
- Adding filter to an specific page/site direction
- Cutting off excerpt with first sentence
- Change URLs in default WordPress slider to relative from absolute
- Modify search form with plugin
- Change add_filter based on Ajax
- How to check which submission button was clicked?
- check, if any “add_action” function contains string XXXXXXXXX
- How to add more than one custom metadata as filter on the post list page?
- Add Default WordPress Formatting To Data From External SQL Tables?
- Joining tables not working in the post editor page
- Auto append text after the title?
- Filter and manipulate the get_current_user() function
- add_filter(‘the_content’, ‘method’) does not trigger my custom method