Search query with quotes

I'm trying to search through WP_Query in wordpress, in custom post types. I have this request$wp_query = Wp_Query([

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.

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.

Share Improve this question edited Jun 7, 2019 at 0:01 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Jun 6, 2019 at 22:26 Kristián StrokaKristián Stroka 1011 bronze badge
Add a comment  | 

1 Answer 1

Reset to default -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() ) {
     $the_query->the_post();
     echo '<li>' . get_the_title() . '</li>';
  }
     echo '</ul>';
     }

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745429521a4627329.html

相关推荐

  • Search query with quotes

    I'm trying to search through WP_Query in wordpress, in custom post types. I have this request$wp_query = Wp_Query([

    13小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信