我目前正在使用Woocommerce为WordPress网站构建自己的自定义高级搜索功能。您应该可以使用过滤器进行搜索:
我目前的进展情况附在下面。这使您可以在URL参数中指定类别标签。返回的帖子将匹配:
/**
* Default arguments
* @var array
*/
$query = array(
'post_status' => 'publish',
'post_type' => 'product',
'posts_per_page' => 10,
);
/**
* Category search
*/
if(isset($_GET['categories']) && $_GET['categories']) {
/**
* Comma seperated --- explode
* @var [type]
*/
$categories = explode(',', $_GET['categories']);
/**
* Add "or" parameter
*/
$query['tax_query']['relation'] = 'OR';
/**
* Add terms
*/
foreach($categories as $category) {
$query['tax_query'][] = array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => $category,
);
} …Run Code Online (Sandbox Code Playgroud)