i have this code that print all woocommerce categories and i want to hide a single cateogry from this loop.
<?php
$get_featured_cats = array(
'taxonomy' => 'product_cat',
'orderby' => 'name',
'hide_empty' => '0',
'include' => $cat_array,
);
$all_categories = get_categories( $get_featured_cats );
$j = 1;
foreach ($all_categories as $cat) {
echo '<div class="col-sm-3 wow fadeInUp ">
<div class="card mb-3" style="">
<div class="row no-gutters align-items-center">';
$cat_id = $cat->term_id;
$cat_link = get_category_link( $cat_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 ) {
echo '<div class="col-md-4 mini-card-categorie-citta" style="background-image: url(' . $image . ')"></div>';
}
echo '<div class="col-md-8">
<div class="card-body">
<a href="'. $cat_link .'"><h6 class="card-title" style="margin-bottom: 0px;">';
echo $cat->name; // Get Category Name
echo '</h6></a>
</div>
</div>
</div>
</div>
</div>';
$j++;
}
// Reset Post Data
wp_reset_query();
?>
There are any way to exclude from this list -> image the category "Traslados" ?
Thanks in advance
You'll need the ID of the category you want to exclude, after that, a simple conditional check before printing out the category. Like so:
$imageCategoryId = 12 //Or whatever your image category id is
foreach ($all_categories as $cat) {
if($cat->term_id !== $imageCategoryId) {
//Display category
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.