您可以添加自定义tax_query
,并将搜索查询传递给它:
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\');