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.


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? – fall3n Jun 9 at 17:25
  • No I didnt..... – Kristián Stroka Jun 11 at 13:15
  • oh, nice downvote :) – fall3n Jun 11 at 14:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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