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>';
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745429521a4627329.html
评论列表(0条)