2016-11-22 78 views
0

在WordPress中,当您想将搜索范围限制为特定帖子类型时,将以下行添加到搜索表单中<input type="hidden" value="product" name="post_type" />其中value包含帖子类型的名称。如果您想使用两种帖子类型进行搜索,该怎么办?Wordpress自定义搜索与多个帖子类型

回答

1

我设法在functions.php文件

function searchfilter($query) { 

if ($query->is_search && !is_admin()) { 
    $query->set('post_type',array('post_type_1','post_type_2')); 
} 

回报$查询添加下列函数来做到这一点; }

add_filter('pre_get_posts','searchfilter');

通知行$query->set('post_type',array('post_type_1','post_type_2'));

这是我通过文章类型作为参数

+0

大答案好友! –

相关问题