You could try something like this below.
Basically, if we are performing a search and it is the main_query (the query that generates the page results) ignore the default search and perform an exact match via the query_where
function custom_product_search_exact_match( $query ) {
global $wpdb;
if ( is_search() && is_main_query() && !empty( $query->query_vars['s'] ) ) {
$search_term = $query->query_vars['s'];
$query->query_vars['s'] = '';
$query->query_where .= " AND ($wpdb->posts.post_title="$search_term")";
}
return $query;
}
add_filter( 'pre_get_posts', 'custom_product_search_exact_match' );
Related Posts:
- How to show terms from another taxonomy
- When should you use WP_Query vs query_posts() vs get_posts()?
- Wp get all the sub pages of the parent using wp query
- How to query for most viewed posts and show top 5
- WP Query where title begins with a specific letter
- WP_Query vs get_posts
- Query Custom Meta Value with Increment
- Get posts by meta data OR title
- Perform query with meta_value date
- WP_Query ordered by custom field that is a date string?
- Multiple search queries on one page
- Pass the same object to multiple widgets in a template with one query
- Retrieve or Query Pages by ID
- How do you query wordpress posts using a math formula between multiple meta field values?
- How to implement time filter to show random post 1 month for one category and 3 months for other categories
- Page navigation doesn’t show when query category
- Empty tax_query array returns an empty array
- How do I search inside specific taxonomies in WordPress
- Pass array of taxonomy terms to wp_query
- Custom category search box for WordPress
- How to find exact match for search term in WP_Query? What is the additional string added in LIKE query in WP_Query?
- Creating a custom search for a specific post type
- How to query a custom post type with a taxonomy filter but display post type archive page?
- Querying on multiple taxonomies pulled from $_GET checkbox array not working?
- Change query_posts to WP_Query in page but does not work
- Custom Query num_rows returns wrong amount
- Editing the default wordpress search
- Slow page loads due to WordPress Core Query
- Query Page Content From Theme Options?
- Modify Search Query if original Query gave no results
- How can I override one post and make it display content for another post?
- Include current post into loop
- Filter Custom Taxonomy Posts
- Filter post query to only show direct children of category
- Get a list of posts by specific category
- How to add custom meta to ‘pre_get_terms’?
- Should I reset $wp_query?
- Why doesn’t my WP Meta Query return any results?
- Filter products on category AND tag
- pre_user_query vs pre_get_posts
- Get posts that match defined arrays of tags
- I need query_posts() to order results first by a meta value and then by post ID
- Add to search posts query array with post IDS which will appear first
- Search has query that will return no results
- WP Query – Search in title or author_name
- How to show post title in content editor in backend?
- My entry results are not consistently alphabetized
- Merge two queries and remove duplicate
- WP Query Relations / Compare
- How can I modify standard search query to include also ACF custom fields values?
- Ordering Posts by parent category, name ascending
- Search Functionality broken by the wp 4.2 update
- Optimising specific Query with ACF meta objects
- How to get several fields from wp_query?
- How to organize a WP_Query’s list of posts by category and display category title?
- Need help setting up a search form for wordpress [duplicate]
- When should you use WP_Query vs query_posts() vs get_posts()?
- How to query post ids liked by the Author
- WordPress Query showing multiple titles
- Query Posts by date range with fixed beginning and end
- custom query to get posts
- Search query alteration not working for meta values
- Search results stuck on page 1
- Advanced Search – Is this possible?
- Rewrite URL custom search query
- How to make posts unqueryable/unpublish posts where ACF relationship field is an unpublished post? [closed]
- Conditional operator OR not working with custom fields
- complex get_posts() query to select child pages
- How to set up hierarchical relationships without using plugins / meta query
- Count posts per taxonomy else change taxonomy if less than x number
- Set front_page programatically after user login via query, while leaving site option alone
- Get posts that do not have the same tags as current
- get term id from term name
- find custom post type post by searching its custom field with my string
- WP_Query to output chosen term and posts with no term assigned
- Redirect Search to Form When No Product Results Are Found
- How to properly use AND / OR in custom search
- Shortcode for custom query not returning results when attributes are added
- WP Job Manager plugin – Listing only the twelve job categories on frontpage order by jobs they have
- How to avoid bypass of search bar rules?
- Yoast primary category query modification
- Hide products in uncategorized category from search results
- Query where ANDing slug values not working
- Getting the post terms ‘wp_get_post_terms’ per post when within the functions.php file
- Posts Query | Query to only show sub categories
- Issues with search after added meta_query
- How to give classname to post if post has no content?
- How to filter query loop block with a search string from the query parameters
- Adding a language rule and displaying posts with a custom taxonomy term on its archive page
- Filtering custom post type list in admin by custom meta key/value
- How to use meta_query to retrieve posts from multiple custom post type
- Block Editor – WordPress 6.1 – CPT Archive Issue – While the title changes in the loop, all records display the same data
- $wp_query->found_posts; returns zero
- Multiple queries and pagination
- post per page for differents post types in a same query
- posts_per_page showing 16 elements instead of 3
- When to use WP_query(), query_posts() and pre_get_posts
- Optimizing AJAX Query with Large Database
- query loop “inherit query from template” prevents setting sort order
- Need help with Query Loop. Need to get current taxonomy term and its posts and group them by a different selected taxonomy term