Read wordpress search exact phrase for more information.
WordPress search exact phrase
When we search for a word or a phrase, all kinds of posts related to the keyword are shown up. This is the most commonly asked question about WordPress search. For instance, let’s take a term you might be looking for and search for ‘search exact phrase’. You end up with posts having the terms ‘search’ or ‘phrase’ or ‘exact’. But, if you want to see results with the search term ‘search exact phrase’, it is possible with a twist in the code.
This can be achieved by altering the WordPress default query by following different techniques as:
- the pre_get_posts
- the query_posts
- the SQL statement filters
- the wp_the_query
Any of the above techniques can be used for WordPress Search Exact Phrase, but ‘pre_get_posts’ is the easiest way. Just by adding a hook ‘pre_get_posts’ in theme’s functions.php, you can alter the default query. Before the actual query is run, this hook should be called after the query variable object is created. This hook gives the programmer to access the query object by reference.
There is a parameter called ‘exact’ which allows setting whether the search query should return results having exactly the searched terms or as set by default. To customize the search to work in exact mode (matching each word from the search terms), you must insert a customized code in your theme’s functions.php file.
Learn more about it by viewing the video:
For all your search needs, alternatively, you can use WP fastest site search plugin from WordPress plugin by Expertrec
- Install WP fastest site search plugin from WordPress plugin store.
- Go to https://cse.expertrec.com/newuser?platform=wordpress.
- Enter your WordPress website URL and click on next->
- The crawl will start in the background.
- Login to your WordPress admin panel.
- In your left panel you must be able to see expertrec’s WordPress plugin, click on that.
- Get your site ID (or) API key from your expertrec control panel ( here ).
- Copy-paste your site id in your WordPress control panel and click on save changes.
- Make sure you have upgraded to a paid plan before 15 days of free trial. (Price begins at 9 USD per month)
- That’s it! Your brand new WordPress search is up and running! Here are snapshots of the search form and the search results pages.
- Snapshot of your WordPress search autocomplete.
- Snapshot of your WordPress search results page.
- Snapshot of your WordPress search spelling error tolerance feature.
- If the plugin method didn’t work, you can add the code from https://cse.expertrec.com/csedashboard/home/code and add it to your wordpress PHP code. Please note that you have to add separately the code <ci-search></ci-search> to a place where you want the search box to appear ( Tip!- Contact our support team to get this done). There might be a one-time fee for integration.