【发布时间】:2022-01-06 05:36:15
【问题描述】:
我正在尝试进行查询,在其中输入页面上已有的产品代码、我对过滤感兴趣的标签代码和分类,但问题是它抛出了我剔除按分类但未按标签过滤的产品,或者更好的是标签是错误的,您认为可能是什么问题?
$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);
【问题讨论】:
标签: wordpress woocommerce filter tags custom-taxonomy