在特定页面上,我希望只对来自两个自定义分类法的术语执行搜索。不是内容或标题。也就是说,用户直接搜索分类术语。
我试图做的是完全重写搜索查询,但它似乎不起作用。
function search_filter_get_posts($query) {
if ( !$query->is_search )
return $query;
$terms = explode(",", $query->query[\'s\']);
$taxquery = array(
\'post_type\' => \'eproduct\',
\'tax_query\' => array(
\'relation\' => \'OR\',
array(
\'taxonomy\' => \'product-type\',
\'field\' => \'slug\',
\'terms\' => $terms,
),
array(
\'taxonomy\' => \'product-features\',
\'field\' => \'slug\',
\'terms\' => $terms,
),
),
);
;
$query = new WP_Query( $taxquery );
}
add_action( \'pre_get_posts\', \'search_filter_get_posts\' );