0
我做了一個自定義查詢以獲得產品變體,但是當我垃圾產品時,它的變體狀態將保持爲publish
,所以如果客戶發生了404
錯誤試圖查看被廢棄的產品變體。 那麼,我如何過濾這些變體以獲得已發佈父代產品的變體?如何僅在母公司產品發佈時獲取產品變體
我的代碼:
<?php
$args = ['post_type' => ['product_variation'],
'orderby' => 'meta_value_num',
'order' => 'DESC',
'post_status'=>'publish',
'product_type'=>'variation',
'meta_query' => [
[
'key' => 'attribute_pa_flower-type',
'value' => $flower_type,
'compare' => '=',
]
]
];
?>
<?php $the_query = new WP_Query($args);?>
<?php if ($the_query->have_posts()) : ?>
<div class="boxes">
<?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
...
是的,這是有效的,我最終做的是得到每個變體的父帖子,並檢查其在while循環內的狀態,但我會更改我的代碼爲你的,因爲它更快 – Mohammad
我沒有找到和WooCommerce功能爲此,我這樣做了我的WP知識。 –