提问者:小点点

Wordpress搜索无法使用超过87个字符的搜索词


我有以下Wordpress搜索设置:

搜索表格。php

 <input type="text" class="search_form clearable" name="s" id="s" autocomplete="off" placeholder="Search Text" />

search.php

 <?php if ( have_posts() && strlen( trim(get_search_query()) ) != 0 ) :
        while ( have_posts() ) :
        set_query_var( 'boxclass', 'full horizontal');
               the_post();
              .
              .
              .
        // If no content, include the "No posts found" template.
        else :
           echo '<div>No search results found</div>';
        endif;
   ?>

现在,

当我搜索87个字符的文本时,请说:

“Lorem ipsum door sit amet,concertetuer adipis elite.Aenean commodo ligula eget dolor.Aenean masa.Cum socis natoque penatibus and magnis dis parturity montes,nasctur ridiculus mus.Donec quam felis,ultricies nec,pellentesque eu,pretium quis,sem.nula consequeat mass quis enim.Donec pede justo,frollilla vel,aliquet nec,vulputat埃吉特,阿库。在埃尼姆·胡斯托、朗卡斯·乌特、伊佩拉、维尼那提斯·维塔、胡斯托。猫咪的口头禅是一种很好的口头禅。整数tincidunt。克拉斯·达皮布斯。万岁。埃尼安·沃普塔特·埃利芬德·泰勒斯。埃尼安·利奥·利古拉,波特提托·欧,康塞卡特“

找到一个post结果。

当我搜索帖子中同样存在的88个字符的文本字符串时,说:
“Lorem ipsum door sit amet,concertetuer adipis elite.Aenean commodo ligula eget dolor.Aenean masa.Cum socis natoque penatibus and magnis dis parturity montes,nasctur ridiculus mus.Donec quam felis,ultricies nec,pellentesque eu,pretium quis,sem.nula consequeat mass quis enim.Donec pede justo,frollilla vel,aliquet nec,vulputat埃吉特,阿库。在埃尼姆·胡斯托、朗卡斯·乌特、伊佩拉、维尼那提斯·维塔、胡斯托。猫咪的口头禅是一种很好的口头禅。整数tincidunt。克拉斯·达皮布斯。万岁。埃尼安·沃普塔特·埃利芬德·泰勒斯。埃尼安·利奥·利古拉、波特提托·欧、康塞库塔”

它返回:未找到搜索结果

如何解决这个问题?Wordpress搜索词的长度有限制吗?


共2个答案

匿名用户

看起来您达到了PHP最大参数长度限制,与wordpress无关。

在_GET中查看URL参数的最大大小

匿名用户

我发现了问题的症结所在。问题在于实际搜索发生的WP核心文件,即。

WP-包括/query.php=

问题如下:

if ( empty( $q['search_terms'] ) || count( $q['search_terms'] ) > 9 ){                    
                     $q['search_terms'] = array( $q['s'] );
                    }

即。根据WP Core方法,如果搜索字符串中包含所有单词,即搜索词(不包括if/the/of etc类型的单词,在函数parse_search_terms()下query.php)计数:

  • 1-9,搜索字符串被拆分为单个单词,所有的搜索词都被单独搜索(使用喜欢子句)在帖子表标题和内容中,这些被合并在一起

例如:

 ((test_posts.post_title LIKE '%Officers%') OR (test_posts.post_content LIKE '%Officers%')) AND ((test_posts.post_title LIKE '%Manager%') OR (test_posts.post_content LIKE '%Manager%'))
  • 0或

例如。

((test_posts.post_title LIKE '%Officers and Managers are working and coordinating into an atmosphere of healthy development in the year 1982 of bright age%') OR (test_posts.post_content LIKE '%Officers and Managers are working and coordinating into an atmosphere of healthy development in the year 1982 of bright age%'))

现在,在我的例子中,*在86个字符中,我的搜索项数组计数为9,因此每个搜索项都在SQL DB中单独搜索,所有搜索都是“和”合并的。*在87个字符中,我的搜索词数组计数为10,因此最终的搜索词没有被拆分为单个词,而是作为单个字符串进行搜索。由于数据库中的字符串之间有一个html标记,因此作为单个字符串,它没有给出post作为结果。

因此,造成逻辑差异的不是字符数,而是$q['search_terms']中的单词数。

希望能有帮助。谢谢