This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: No results for "M&M", but results for "M&"

Home Forums Product Support Forums Ajax Search Pro for WordPress Support No results for "M&M", but results for "M&" Reply To: No results for "M&M", but results for "M&"

#24186
Ernest MarcinkoErnest Marcinko
Keymaster

Hi,

I see the issue now, it is not the ‘&’ character, but the apostrophe.

Searching for:

M&M’s

..returns results, but searching:

M&M's

..does not. It’s a different apostrophe character. Assuming that every apostrophe is stored like that, I would suggest this custom code then:

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; 
}