I'm trying to search through WP_Query in wordpress, in custom post types. I have this request

$wp_query = Wp_Query(['post_type' => 'property', 's' => 'test']);

This works perfect. but when my property has title with apostrophe like test's, it doesnt work, after enter into search page in my search attribute I got test\'s, and when I try to find posts by this attribute that doesnt work, also when I hardcode change search string without backslash.

Any ideas how to solve this? With some custom filter or something like that? Something about more complex search with WP_Query.

1 Answer 1


using the \' escape works for me, so whatever is causing your issue is something else with your website. I checked with the code below:

$the_query = new WP_Query( ['post_type' => 'post', 's' => 'Hello\'s'] );
if ( $the_query->have_posts() ) {
  echo '<ul>';
  while ( $the_query->have_posts() ) {
     echo '<li>' . get_the_title() . '</li>';
     echo '</ul>';
  • did you figure this out?
    – brothman01
    Commented Jun 9, 2019 at 17:25
  • No I didnt..... Commented Jun 11, 2019 at 13:15
  • oh, nice downvote :)
    – brothman01
    Commented Jun 11, 2019 at 14:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.