【发布时间】:2020-12-02 14:51:33
【问题描述】:
我有一个名为“产品类型”的 WooCommerce 产品类别,我试图列出该类别下的所有类别,但不列出这些类别的子类别。例如,我有:
- 产品类型
- 硬质合金铣刀
- 钓鱼工具
- 儿童类别
我希望它列出“Carbide Mills”和“Fishing Tools”,而不是“Child Category”。
这是我的代码:
<ul>
<?php $terms = get_terms(
array(
'taxonomy' => 'product_cat',
'hide_empty' => false,
'child_of' => 32,
'post__not_in' => 25,
'depth' => 1,
'include_children' => false,
)
);
// Check if any term exists
if ( ! empty( $terms ) && is_array( $terms ) ) {
// Run a loop and print them all
foreach ( $terms as $term ) { ?>
<a href="<?php echo esc_url( get_term_link( $term ) ) ?>">
<li data-mh="234908ju243">
<?php echo $term->name; ?>
</li>
</a><?php
}
} ?>
</ul>
但它仍然返回“子类别”。我不确定为什么将深度限制为“1”并将“include_children”设置为“false”并不能解决问题。
【问题讨论】:
标签: php wordpress woocommerce hierarchical-data taxonomy-terms