Ivory search plugin enhances the search form for those cases:
https://wordpress.org/plugins/add-search-to-menu/
Thanks for the reply but I have wrote custom code using AJAX so I need custom functions.
@corrinarusso thanks for your time but let me know how could you escape here, see code –
$query = new WP_Query(array('post_type'=>'services','posts_per_page'=>-1,'s'=>$searchVal));
$data = array();
if($query->have_posts()):
while($query->have_posts()): $query->the_post();
$location = get_field('service_location');
$data[] = array(
'title' => get_the_title(),
'lat' => $location['lat'],
'lng' => $location['lng'],
'type' => 'service',
"path" => get_the_permalink()
);
endwhile;
endif;
$developments = $data;
unset($data);
echo json_encode($data);
@abuomama
Untested, and I don’t know if there is already a native function to use this, but you could try to replace your query like this :
$escapesearchVal = mysql_real_escape_string($searchVal);
but sanitize_text_field is probably safer and would already includes the escape :
https://developer.wordpress.org/reference/functions/sanitize_text_field/
https://developer.wordpress.org/reference/hooks/sanitize_text_field/
like this :
$escapesearchVal = sanitize_text_field ( $searchVal );
$query = new WP_Query(array('post_type'=>'services','posts_per_page'=>-1,'s'=>$escapesearchVal));
....
@corrinarusso @a2hostingrj
I think you unable to understand my question completely so I recorded a video, watch – https://youtu.be/5Y6ltSROOlg
@abuomama
Hmmm, tbh I am not a fan of the the solution described here :
https://wordpress.org/support/topic/search-with-special-characters-doesnt-work/
It’s too explicit imo.
That said, did you try it out ? and does it work ?
As I said earlier, I’m pretty sure the sanitize_text_field does the same thing.
Did you try it ?
$escapesearchVal = sanitize_text_field ( $searchVal );
$query = new WP_Query(array(‘post_type’=>’services’,’posts_per_page’=>-1,’s’=>$escapesearchVal));
….
@corrinarusso
I tried but nothing work, so I have created a field for keywords and then search worked as per I need