admin管理员组文章数量:1426072
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 badge1 Answer
Reset to default -1using 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>';
}
本文标签: Search query with quotes
版权声明:本文标题:Search query with quotes 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745429520a2658264.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论