I'm trying to remove a product category term slug called "outlet" from my loop and I saw this post Exclude a WooCommerce product category from a WP_Query
I tried in my code, but I'm missing something, is there a way to remove a specific product category?
<?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();}
?>
There are some mistakes and missing things in your code. Try the following instead:
Tested and works.