php - How to strip/replace a slanted double quotes ″ with " in wordpress search query?

309

I'm trying to replace slanted double quotes ″ with regular double quotes " in wordpress (woocomerce) search query because the first example returns no products.

Example search:

CUBE ACID SIC PURE 28″ RILink (no results)
CUBE ACID SIC PURE 28" RILink (correct result)

I tried to replace the ″ characted with this code usingget_search_query filter:

add_filter('get_search_query', 'my_search_query');

function my_search_query( $s ) {
  $characters = '″'; // Replace this
  $replace_with = '"'; // with this

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

but that only changed the search results text to CUBE ACID SIC PURE 28""" RILink and the search query url stayed the same ?s=CUBE+ACID+SIC+PURE+28″+RILink&post_type=product with the incorrect double quote character.

What is the correct way to replace quotes in search query url so the search returns results as expected?

People are also looking for solutions to the problem: How do I find ftp information of page to query via php?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.