我正在嘗試獲取當前類別中的所有產品 sku。到目前為止,我有這個代碼,它只讓我得到 ID。我也嘗試過使用,meta_query但出現了一些錯誤。我對門戶網站和其他網站進行了一些研究,但我根本沒有得到它。我需要做的是在 all_ids 陣列中顯示所有當前的 Woocommerce 產品類別產品父 sku。
到目前為止的代碼
$all_ids = get_posts( array(
'post_type' => 'product',
'numberposts' => -1,
'post_status' => 'publish',
'fields' => 'ids',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => 'tenisky',
'operator' => 'IN',
)
),
) );
輸出將資料匯入到我的 HTML 資料層中。
<?php echo "'" . implode ( "', '", $all_ids ) . "'"; ?>
先感謝您!
uj5u.com熱心網友回復:
我認為您應該能夠使用get_post_meta以下方法解決此問題:
$all_ids = get_posts( array(
'post_type' => 'product',
'numberposts' => -1,
'post_status' => 'publish',
'fields' => 'ids',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => 'tenisky',
'operator' => 'IN',
)
),
) );
$idsku = [];
for ($index = 0; $index < count($all_ids); $index ) {
$idsku[$index] = get_post_meta($all_ids[$index], '_sku', true);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/352307.html
標籤:php WordPress的 求购
