首页 > 解决方案 > AND 关系在 Search and Filter Pro 使用 WP Query 的自定义搜索中不起作用

问题描述

我正在使用 Search and Filter Pro 插件根据各种帖子元和分类法获取搜索结果,我并没有完全使用插件的整个界面,只使用它的自定义查询方法:

https://searchandfilter.com/documentation/search-results/custom/

我将搜索和过滤器附加到该WP_Query部分,如下所示:

$premium_args = array(
                "s" => $_GET['q'],
                'posts_per_page' => 20, 
                'paged' => 1, 
                'post_type' => array( 'contactdirectory'),
                'orderby' => 'title',
                'order'   => 'ASC',
);  

$premium_args['search_filter_id'] = 166;

在插件中,我AND为该搜索和过滤器实例设置了“字段关系:”。

但是它没有按预期工作,这里有一个例子:

https://indiadairy.com/?s=&p_type=cd&_sft_Industries=equipment-manufacturers&_sfm_state=Maharashtra

_sft_Industries=equipment-manufacturers在那里,然后但在搜索结果中,您可以看到某些结果对于分类法和“非政府组织”_sfm_state=Maharashtra具有不同的值,而它应该只返回满足传递给两个参数的值的结果。IndustriesDairy Plants

我尝试添加

'meta_query' => array(
   'relation' => 'AND',
)

它不起作用,正如我所料,因为它是用于在WP_Query参数中手动传递的元查询。

标签: wordpress

解决方案


推荐阅读