WordPress   

Get all top level product categories including custom field and thumbnail

<div class="product-categories">
	<?php $productCats = get_terms('product_cat', array('hide_empty' => 0,'meta_key'   => 'order', 'orderby'    => 'meta_value_num', 'parent' =>0)); 
		foreach($productCats as $productCat) :
		//remove uncategorized from loop
		if( $productCat->slug == 'uncategorized' ){
           continue;
		}
		$productCategoryImage = wp_get_attachment_image( get_term_meta( $productCat->term_id, 'thumbnail_id', true ), 'full' );			
		?>
		<div class="product-category">
			<?php if($productCategoryImage): ?>
			<div class="product-category-img">
			<?php echo $productCategoryImage; ?>
			</div>
			<?php endif ?>
			<a class="product-category-title" href="<?php echo get_term_link( $productCat->slug, $productCat->taxonomy ); ?>"><?php echo $productCat->name; ?></a>
			<p class="product-category-text"><?php echo $productCat->description; ?></p>
			<p><?php the_field('category_subtitle'); ?></p>
		</div>
	<?php endforeach; ?>
</div>
Need a helping hand in fixing your website issues?

If you are facing any problems in implementing these code snippets and tutorials, you can hire us to fix your website issues.

Hire Us