Loop through taxonomies and display taxonomy acf image

Loop through all terms of a taxonomy and display the advanced custom field acf image object as a taxonomy image.

<div id="box-container">	
    <?php 
		// loop through terms of the Markets Taxonomy
		$getArgs = array(
		'parent'       => 0,
		'order' => 'DESC',
		'orderby' => 'count',
   		'hide_empty'    => false,
		);
		// get the taxonomy we are going to loop through. 
		$taxonomy = get_terms('markets', $getArgs);
			
	// Start the loop through the terms
	foreach ($taxonomy as $term) { 
          
 		// Get acf field Name
        $image = get_field('market_image', $term ); 
        $url = $image['url'];
        $title = $image['title'];
        $alt = $image['alt'];
     	// which size?
        $size = 'large';
        $thumb = $image['sizes'][ $size ];
        ?>
      
        <div class="boxes">
        	<div class="box-overlay"><?php echo $term->name; ?></div><!-- box overlay -->
            <img src="<?php echo $thumb; ?>" alt="<?php echo $alt; ?>" title="<?php echo $title; ?>" />
        </div><!-- boxes -->
            
<?php } // end foreach ?>
            
</div><!-- box container -->

 

3 thoughts on “Loop through taxonomies and display taxonomy acf image

Leave a Reply

Your email address will not be published. Required fields are marked *

47 − = 45