0
我試圖根據woocommerce中給定的父產品類別顯示所有子產品類別的數據。我可以通過WordPress功能獲得一系列產品類別ID,get_term_children
。WordPress的get_category不工作forloop
$category_children = get_term_children(25, 'product_cat');
foreach ($category_children as $category_id) {
echo '<br> cat ID' . $category_id;
echo '<pre>';
print_r(get_category($category_id));
echo '</pre>';
}
問題是當我嘗試在循環中顯示該數據。在這種情況下,我有兩個子產品類別。我的循環只會返回除最後一個ID以外的所有數據。這是我得到的。奇怪的是,我可以看到循環抓取所有來自$category_children
的ID。
cat ID 26
WP_Term Object
(
[term_id] => 26
[name] => Shirts
[slug] => shirts
[term_group] => 0
[term_taxonomy_id] => 26
[taxonomy] => product_cat
[description] =>
[parent] => 25
[count] => 2
[filter] => raw
[meta_value] => 0
[cat_ID] => 26
[category_count] => 2
[category_description] =>
[cat_name] => Shirts
[category_nicename] => shirts
[category_parent] => 25
)
cat ID 27
哪裏是爲27日凌晨WP_Term對象我沒有使用正確get_category
或者,我需要取消它還是什麼?