Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Cannot Find Target Term when Apostrophe and 's added. › Reply To: Cannot Find Target Term when Apostrophe and 's added.
Hi,
1. I’m afraid that is not possible. This kind of front-end search (like the browser CTRL + F) is best to have custom coded for the specific page. It is usually not too complicated, but best to ask a developer about specific details.
This plugin is to search back-end objects (via database) and return them as singular results – such as individual posts/pages etc.. – so it would only return the single page as the result. The CTRL+F is a pure front-end javascript search.
2. The apostrophes are generally not touched within the phrase the user enters, so it can match items with the apostrophe in it. If the word hilda’s is not present in the text, then it will not match. The easiest way to deal with them is via using a custom code to get rid off the unwanted characters, and replace them preferably with a space character.
Try adding this code to the functions.php file in your theme/child theme directory – make sure to have a full server back-up first for safety. For more details you can check the safe coding guidelines.
add_filter('asp_search_phrase_before_cleaning', 'asp_replace_characters', 10, 1);
add_filter('asp_query_args', 'asp_replace_characters', 10, 1);
function asp_replace_characters( $s ) {
$characters = "'’‘’"; // Type characters one after another
$replace_with = ' '; // Replace them with this (space by default)
if ( is_array($s) ) {
if ( isset($s['s']) && !$s['_ajax_search'] )
$s['s'] = str_replace(str_split($characters), $replace_with, $s['s']);
} else {
$s = str_replace(str_split($characters), $replace_with, $s);
}
return $s;
}