基于分类法的类似/部分结果的Wordpress搜索

问题描述 投票:0回答:1

我正在编写一个我在Wordpress中创建的目录。该目录作为一个名为“agents”的自定义帖子类型,并拥有自己的名为“agent_location”的分类。每个代理都有多个“agent_location”条款添加到其列表中。每个agent_location术语仅连接到一个“代理”。每个agent_location都是英国邮政编码的开头。例如“AB1 1”或“AB11 3”等。

我正在使用WPAS Wordpress高级搜索(http://wpadvancedsearch.com/)来创建搜索表单。我希望最终用户能够输入他们的整个邮政编码,例如AB1 1AA,并且会出现具有“AB1 1”一词的代理商帖子,而不是列出“AB11 3”的代理商帖子。基本上搜索需要忽略输入的任何搜索的最后2位数。目前我创建的表单如下所示:

function agents_search_form() {
$args = array();
$args['wp_query'] = array('post_type' => 'agents',
                          'posts_per_page' => -1);

$args['fields'][] = array('type' => 'search',
                          'title' => 'Search',
                          'placeholder' => 'Enter search terms...',
                            'pre_html' => '<div class="hiddenField searchRow"><div class="searchWrap">',
                            'post_html' => '</div>');

$args['fields'][] = array( 'type' => 'submit',
                           'class' => 'button',
                           'value' => 'Search' ,
                            'pre_html' => '<div class="searchBTNWrap">',
                            'post_html' => '</div></div>');

$args['fields'][] = array('type' => 'taxonomy',
                          'taxonomy' => 'agent-location',
                          'format' => 'text');


register_wpas_form('agents-form', $args); 
}
 add_action('init', 'agents_search_form');  

当您使用表单时,它可以完美地工作,但不包括邮政编码的最后2位数字。如果您输入整个邮政编码,则不会找到搜索结果。我想帮助创建一个搜索表单,允许用户在搜索中输入他们的整个邮政编码并仍然得到结果。

我对解决方法的想法持开放态度。请记住:

  • 每个代理商帖子列出的邮政编码遍布英国各地。没有中心位置,所以“半径”地图搜索将无法工作。
  • 如果有帮助,我很乐意将分类标准直接作为自定义字段移动到帖子中
  • 该网站已经上线,所以我不想重新创建整个网站,但我很乐意编写新的解决方案或使用插件,如果它能得到我想要的结果。该网站目前使用Gravity表格,WPAS,Beaver Builder和ACF pro。
  • 很大一部分网站访问者是盲目或视力不佳的,所以解决方案必须是“屏幕阅读器友好”

提前致谢

wordpress search closest wpas partial-matches
1个回答
0
投票

我最终使用了Relevanssi插件 - https://wordpress.org/plugins/relevanssi/并将其与WPadvancedsearch结合使用,它实际上可以很好地协同工作并让我做我需要的一切。

© www.soinside.com 2019 - 2024. All rights reserved.