すべての商品を属性と一致するカテゴリに登録する必要があります。Woocommerce - 特定の属性を持つカテゴリの商品を取得する
ここに私のコード:
$title = isset($instance['title']) ? $instance['title'] : '';
$car_type = isset($instance['cartype']) ? $instance['cartype'] : 'usato';
$car_brand = isset($instance['carbrand']) ? $instance['carbrand'] : '';
$limit = isset($instance['limit']) ? $instance['limit'] : null;
$order = $instance['order'];
$carousel = $instance['carousel'];
$query_args = [
'post_type' => 'product',
'post_status' => 'publish',
'product_cat' => $car_type
];
// Ordino i risultati
if ($order == 'random') {
$query_args['orderby'] = 'random';
} else {
$query_args['orderby'] = 'name';
$query_args['order'] = $order;
}
// Devo limitare il numero di risultati?
if ($limit) {
$query_args['posts_per_page'] = $limit;
}
if ($car_brand != '') {
$query_args['tax_query'] = array(
array(
'key' => 'pa_marca',
'value' => 'nike',
'field' => 'slug',
'compare' => '='
)
);
}
問題は、私はいつもそのカテゴリとその属性を持つ製品があっても0結果を得ることです。
クエリをどのように変更する必要がありますか?
私はゼロの結果を得ています。少なくとも1つは存在すると確信しています –