Get the terms by image and child

<nav class="frntre-nav">
	<?php //$pro = get_the_terms( get_the_ID(), 'product_cat' );
  // $term = get_queried_object();
	$terms = get_terms( array(
    'taxonomy' => 'product_cat',
    'parent'    => 0,
    'hide_empty' => false
) );

/*	 echo "<pre>";
	 print_r($terms)*/ ?>
<ul id="primary-menu" class="">
	<?php foreach ($terms as $value) { 

		 $child_arg = array( 'hide_empty' => false, 'parent' => $value->term_id );
    $child_cat = get_terms( 'product_cat', $child_arg );



  $thumbnail_id = get_term_meta( $value->term_id, 'thumbnail_id', true ); 
		  $image = wp_get_attachment_url( $thumbnail_id ); ?>

	<li class=" menu-item menu-item-type-taxonomy menu-item-object-product_cat"> <a href="<?php echo $value->slug; ?>">
 <?php if ( $image ) {
		    echo '<img src="' . $image . '" alt="' . $cat->name . '" />';
		} ?>
   <span class="menu-text"><?php echo $value->name; ?></span></a></li>

<?php 
  
        foreach( $child_cat as $child_term ) { ?>
           <a href="<?php echo $child_term->slug; ?>"> <?php echo $child_term->name ?> </a><br/>  
      <?php 
        }
        ?>
    

<?php } ?>

</ul>
 



</nav>

Leave a comment