2016-11-22 60 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

大答案好友! –

相關問題