Woocommerce - search in product category by keyword
This is my search form. Im use woocommerce. And need to search products by keywords and categories.
this is my filter code
function advanced_search_query($query)
{
if($query->is_search()) {
// category terms search.
if (isset($_GET['category']) && !empty($_GET['category'])) {
$query->set('tax_query', array(array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array($_GET['category']) )
));
}
return $query;
}
}
add_action('pre_get_posts', 'advanced_search_query', 1000);
but wordpress show all products from all categories by keyword. WHAT IS WRONG?