【发布时间】:2020-10-06 08:51:35
【问题描述】:
我正在尝试从我的循环中删除一个名为“outlet”的产品类别术语 slug,我看到了这篇帖子 Exclude a WooCommerce product category from a WP_Query
我尝试了我的代码,但我遗漏了一些东西,有没有办法删除特定的产品类别?
<?php
$get_parents_cats = array(
'taxonomy' => 'product_cat',
'parent' => 0,
'number' => '9',
'hide_empty' => false,
'tax_query' => array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => array( 'outlet' ),
'operator' => 'NOT IN',
),
);
$categories = get_categories( $get_parents_cats );
foreach ($categories as $cat) {
$cat_id = $cat->term_id;
$cat_link = get_category_link( $cat_id );
$term_link = get_term_link( $cat->term_id );
$thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true ); // Get Category Thumbnail
$image = wp_get_attachment_url( $thumbnail_id );
if ( $image ) {?>
<div class="wrapper">
<img src="<?php echo $image; ?>"/>
<a href="<?php echo get_term_link($cat->slug, 'product_cat') ?>">
<div class="title">
<h3><?php echo $cat->name; ?></h3>
</div>
</a>
</div>
<?php
}
wp_reset_query();}
?>
【问题讨论】:
-
tax_query 选择帖子,基于它们是否与那些特定的分类术语相关联。我怀疑您的 product_cat 术语是否以这种方式自我引用。
标签: php wordpress woocommerce custom-taxonomy taxonomy-terms