我正在编写一个我在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位数字。如果您输入整个邮政编码,则不会找到搜索结果。我想帮助创建一个搜索表单,允许用户在搜索中输入他们的整个邮政编码并仍然得到结果。
我对解决方法的想法持开放态度。请记住:
提前致谢
我最终使用了Relevanssi插件 - https://wordpress.org/plugins/relevanssi/并将其与WPadvancedsearch结合使用,它实际上可以很好地协同工作并让我做我需要的一切。