You want to use the pre_get_posts
action to modify the search query on the server side. The pre_get_posts
Codex have some examples to get you started.
To target the main search query, try this:
function my_search_filter( $query ) {
if ( ! is_admin() && $query->is_main_query() ) {
if ( $query->is_search ) {
// Use $query->set(); to do stuff here.
}
}
}
add_action( 'pre_get_posts', 'my_search_filter' );
Related Posts:
- Can I force WP_Query to return no results?
- Post_count only shows the number of results per page
- WP Query where title begins with a specific letter
- Search custom taxonomy term by name
- Order Search Results Page by meta_value If no Value Return Remaining Results
- Tracing the life of a query
- Want to redirect if search query match exact title of any post
- Pagination not working for Custom search form & custom result template
- How to support multiple search terms query within one process?
- Pagination broken when merging search results with additional WP_Query
- Custom search form with empty parameters
- How to search by title or tags exclusively?
- WordPress search exact match
- Pagination wont work with search results template [duplicate]
- How do I search WordPress by different fields without a plugin?
- Multiple keyword search
- Using next/previous_posts_link with customised search
- WordPress custom search form with pre_get_posts not work
- Search – Ajax – Alter Query Parameters with Pagination
- Add custom search results to main WP search [duplicate]
- Multiple search queries on one page
- tax_query shows no results if nothing is selected
- Searching through different categories on different pages code is not working
- WP Query search for attachments and their exact title
- WP_Query’s “request” SQL Query
- Including only current user’s posts in search
- is_search was called incorrectly
- How do I search inside specific taxonomies in WordPress
- Modifying the Search Results
- Custom category search box for WordPress
- Refine search results using WP_Query
- How to find exact match for search term in WP_Query? What is the additional string added in LIKE query in WP_Query?
- Search Posts with Custom Fields as query
- Complex date range with WP_Query and BETWEEN
- Creating a custom search for a specific post type
- Custom Search Result Page displaying only 1 result.
- How to loop for every result found in the_content() when using the search query?
- Assigning a meta_query value based on regexp to wp_query fails
- showing all search result in one template
- Querying on multiple taxonomies pulled from $_GET checkbox array not working?
- Is there any advantage of using default WordPress Search instead of creating a custom one?
- WP_Query Not Recognizing Taxonomy Parameter in Custom Search
- Search pages that are a child of the current page
- Include tags in WP_Query
- Search for multiple tags?
- Custom Search Not Consistent with Results
- wp_query ‘s’, search filter with pagination is not working
- Editing the default wordpress search
- How to use wp_query to post count by search term > group post count by date > convert to json. (ex. result 12-21-2020 – 343)
- Multiple Search Terms WP_Query
- Extend product search with meta in WooCommerce
- WP Query Args – Title or Taxonomy Value
- Display Search Results by tag_ID in my search.php
- How to debug none working search query?
- getting posts by tags
- Add to search posts query array with post IDS which will appear first
- Custom Post Type WP_Query with filters and search
- Search with WP_Query, but ignore href URLs in anchor tags?
- WordPress search page pagination displaying but not functional
- Search has query that will return no results
- WP Query – Search in title or author_name
- Limit default Search query to post_title
- Get posts by similar names and categories
- Logging search queries for logged-in users
- How to show terms from another taxonomy
- Search Field that allows options of “Match any keyword” or “Match all keywords”
- Order & Orderby clause not working with custom query
- How can I modify standard search query to include also ACF custom fields values?
- A very strange problem with search query
- Search format not matching taxonomy query
- How to make the default WordPress search return borader results
- Search Functionality broken by the wp 4.2 update
- WordPress WP_Query offset parameter not working with search parameter
- Custom search (wp query by custom fields)
- WordPress WP_Query Array Custom search via taxonomies
- Custom Search Query – include only custom fields and title
- $wp_query when new WP_Query
- Need help setting up a search form for wordpress [duplicate]
- Search Query that Includes Custom Table
- Manipulating a query
- Custom search: Search posts but display parent page in results
- Query posts by custom fields
- Searching in specific custom post type
- Search (Custom Form, Custom Search Result)
- Help with showing text when something is entered in my search bar
- Why does WP_Query not search for two ‘meta_query’ keys separated with OR?
- Filtering product search results using tags
- Using ‘meta_query’ with the ‘pre_get_posts()’ hook disables searching for post titles
- WordPress WP_Query Search (‘s’) With Multiple Search Terms
- How does Show Posts based on a keyword search work in WP_Query
- Search query alteration not working for meta values
- Search results stuck on page 1
- Custom Taxonomy in custom REST API search
- Advanced Search – Is this possible?
- How to include custom fields in wordpress search
- Extend search query to search meta keys values based on search string
- AJAX multiple search boxes not merging with array merge
- Removing filename searches when searching attachments
- Modify WordPress Search
- Rewrite URL custom search query