过滤器 woocommerce 的问题,按标签过滤,而不是在分类法中

Problem with filter woocommerce, filter by tags, not in and taxonomy

我正在尝试进行查询,在其中输入页面上已有的产品代码、我感兴趣的过滤标签代码和分类法,但问题是它让我排除按分类法过滤但未按标签过滤的产品,或者更好的是标签是错误的,在您看来可能是什么问题?

$terms = get_term_by('name', $_GET['category'], 'product_cat');
            $args = array(
                'post_type' => 'product',
                'post_status' => 'publish',
                'post__not_in' => $_GET['products'],
                'posts_per_page' => $_GET['n_products'],
                'orderby' => 'rand',
                'tag__in' => $_GET['tag_ids'],
                'tax_query' => array(
                    array(
                        'taxonomy' => 'product_cat',
                        'field'    => 'term_id',
                        'terms'     =>  $terms->term_id,
                        'compare' => '=',
                    ),
                )
            );
            $query = new WP_Query($args);

努力改变。

'taxonomy' => 'product_cat', 

'taxonomy' => 'product_tag',

试试下面的代码。

$terms = get_term_by('name', $_GET['category'], 'product_cat');
$product_tag = get_term_by('name', $_GET['category'], 'product_tag');

$args = array(
    'post_type' => 'product',
    'post_status' => 'publish',
    'post__not_in' => $_GET['products'],
    'posts_per_page' => $_GET['n_products'],
    'orderby' => 'rand',
    'tag__in' => $_GET['tag_ids'],
    'tax_query' => array(
        array(
            'taxonomy' => 'product_cat',
            'field'    => 'term_id',
            'terms'     =>  $terms->term_id,
            'compare' => '=',
        ),
         array(
            'taxonomy' => 'product_tag',
            'field'    => 'term_id',
            'terms'     =>  $product_tag->term_id,
            'compare' => '=',
        ),
    )
);
$query = new WP_Query($args);