admin管理员组文章数量:1123797
I want that my search page give results of posts (that i want that show) and taxonomy
The code to get just two type of posts:
function searchfilter($query) {
if ($query->is_search && !is_admin() ) {
$query->set('post_type',array('lesson','series'));
}
return $query;
}
add_filter('pre_get_posts','searchfilter');
I want it to look for taxonomy too Thanks
I want that my search page give results of posts (that i want that show) and taxonomy
The code to get just two type of posts:
function searchfilter($query) {
if ($query->is_search && !is_admin() ) {
$query->set('post_type',array('lesson','series'));
}
return $query;
}
add_filter('pre_get_posts','searchfilter');
I want it to look for taxonomy too Thanks
Share Improve this question edited Dec 18, 2017 at 21:05 Johansson 15.4k11 gold badges43 silver badges79 bronze badges asked Dec 18, 2017 at 17:52 user133503user133503 312 bronze badges1 Answer
Reset to default 1You can add a custom tax_query
to your filter, and pass the search query to it:
function searchfilter($query) {
if ($query->is_search && !is_admin() ) {
$s = $query->get( 's' );
$query->set('post_type', [ 'lesson', 'series' ] );
$query->set(
'tax_query',
[
[
'taxonomy' => 'your-taxonomy',
'field' => 'name',
'terms' => $s ,
]
]
);
}
return $query;
}
add_action('pre_get_posts','searchfilter');
本文标签: filtersSearch by type posts and taxonomy
版权声明:本文标题:filters - Search by type posts and taxonomy 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736599520a1945189.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论