【问题标题】:WordPress post search with ignoring apostropheWordPress帖子搜索忽略撇号
【发布时间】:2018-08-15 06:18:32
【问题描述】:

我正在尝试搜索 wp_posts 表中的帖子

$searchValue = $request->get_param("s");
$wpQueryPosts = new \WP_Query([
            'post_type'     => 'post',
            'posts_per_page' => -1,
            'cat'           => 9,
            's' => $searchValue,
]);

$postsPosts = $wpQueryPosts->get_posts();

问题是当我搜索带有撇号的单词时,它没有被正确搜索。如果我搜索 don 我得到正确的结果,当我搜索 don't 时我没有得到任何结果。尽管我知道标题和内容中有 don't 的帖子。我发现了很多类似的问题,但没有一个有明确的答案。

另外,我怎样才能为 dontdon't 获得相同的结果

问题是如果数据库中的单词包含撇号,它不会出现在结果中

【问题讨论】:

  • 如果您尝试先清理输入内容会怎样? $searchValue = sanitize_text_field($searchValue) 之类的东西;或$searchValue = urldecode($searchValue)
  • 问题是如果数据库中的单词包含撇号,它不会出现在结果中
  • 那么请把它放在你上面的问题中。在您的原始帖子中,您说问题是当查询有撇号时它不显示,而不是数据库。

标签: php wordpress


【解决方案1】:

这应该可以完成工作:

$searchValue = html_entity_decode( $searchValue, ENT_QUOTES );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-07
    • 2016-04-23
    • 2011-05-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多