【问题标题】:Wordpress Search breaking after apostrophe撇号后的 Wordpress 搜索中断
【发布时间】:2020-06-03 22:19:22
【问题描述】:

我正在尝试在我的网站上调试一些关于搜索的行为。发生的事情是我想找到类似:What's your Customers' Love Language?,如果我输入What',它将显示它。问题是,只要我在撇号后输入任何内容,它就会突然找不到我的帖子。

所有具有此类标题的帖子都会发生这种情况。

这是我的搜索表单的代码(使用this 主题):

    <div class="search">
                <form role="search" action="<?php echo esc_url(home_url('/')); ?>" method="get">
                    <input type="text" name="s" class="<?php echo implode(' ', $classes); ?>" value="<?php the_search_query(); ?>" placeholder="<?php _e('Search...', 'bunyad'); ?>"/>
                    <button class="search-button" type="submit"><i class="fa fa-search"></i></button>
                </form>
            </div> <!-- .search -->

奇怪的是它可以识别撇号,所以我认为我不需要对特殊字符进行清理。它使用默认的 WP 搜索,没有添加任何额外的东西,所以我真的很难过。

我们将不胜感激任何可以提供的帮助。谢谢

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    似乎 Wordpress 运行 wptexturize() 函数,该函数将引号转换为智能引号,因此您看到的是 而不是 ' 因此,当您搜索 what’s 时不会返回任何内容,因为尽管帖子的拼写是这样的实际上它的拼写是what's

    解决此问题的方法是通过将 add_filter('run_wptexturize', '__return_false'); 在您的 function.php 文件中。


    查看这里了解更多信息:

    Wordpress replacing single quotes with search-unfriendly ones

    Code Reference - wptexturize()

    Disable wptexturize()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多