привет, я хочу показать связанные продукты на основе моего пользовательского запроса, но я просто хочу показать продукты «in_stocks», а meta_query не работает с tax_query. кто-нибудь может мне помочь?
$query_args = array(
'posts_per_page' => 10,
'no_found_rows' => 1,
'post__not_in' => array( $product->get_id()),
'post_status' => 'publish',
'post_type' => 'product',
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'product_cat',
'field' => 'id',
'terms' => $cats_array
),
array(
'taxonomy' => 'product_tag',
'field' => 'id',
'terms' => $tags_array
) )
);
Чтобы удалить товары, которых нет в наличии, из пользовательского запроса WP, вам необходимо добавить дополнительный массив в запрос налога на поездку следующим образом:
$query_args = array(
'posts_per_page' => 10,
'no_found_rows' => 1,
'post__not_in' => array( $product->get_id() ),
'post_status' => 'publish',
'post_type' => 'product',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'product_visibility',
'field' => 'name',
'terms' => array('outofstock'),
'operator' => 'NOT IN'
),
array(
'relation' => 'OR',
array(
'taxonomy' => 'product_cat',
'field' => 'id',
'terms' => $cats_array
),
array(
'taxonomy' => 'product_tag',
'field' => 'id',
'terms' => $tags_array
)
)
),
);
Или также, возможно, используя метазапрос таким образом:
$query_args = array(
'posts_per_page' => 10,
'no_found_rows' => 1,
'post__not_in' => array( $product->get_id() ),
'post_status' => 'publish',
'post_type' => 'product',
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'product_cat',
'field' => 'id',
'terms' => $cats_array
),
array(
'taxonomy' => 'product_tag',
'field' => 'id',
'terms' => $tags_array
)
),
'meta_query' => array(
'key' => '_stock_status',
'value' => 'outofstock',
'compare' => '!='
)
);
Он должен работать.
Связано: Показывать только товары WooCommerce со склада с помощью WP_Query