Support

Account

Home Forums Add-ons Gallery Field Getting taxonomy values from image

Solved

Getting taxonomy values from image

  • I’m using another plugin called Enhanced Media Library which allows you to assign an image in the media library to a custom taxonomy. The default taxonomy is “media_category”.

    I’m trying to get the custom taxonomy terms associated with the images in the gallery field.

    I am familiar with the get_terms function but I can’t figure out how to associate it with the images in the field. If anyone could shed light that would be greatly appreciated.

    Here’s my code now.

    <?php
    					 
    				
    $portfolio_images = get_field('portfolio_gallery');
    					
    foreach( $portfolio_images as $portfolio_image ):
    					
    				 
    ?>
    						
    	<li class="gallery-item" data-myorder="<?php echo $i; ?>">
    	    <img src="<?php echo $portfolio_image['sizes']['portfolio-thumbnail']; ?>" alt="<?php echo $portfolio_image['alt']; ?>" />
    	    <div class="mask">
    	       <a class="mask-link" href="<?php echo $portfolio_image['url']; ?>">
    	       <div class="mask-content">
    	       <h4><?php echo $portfolio_image['title']; ?></h4>
    		<p><?php echo $portfolio_image['caption']; ?></p>
    		</div>
    </a>
    	</div>
    </li>
    						
    <?php  endforeach; ?>
  • Hi @itrogers

    You can get the image ID like so:
    $portfolio_image['ID'];

    With the ID, you can load the terms related to it like so:
    get_the_terms( $portfolio_image['ID'], 'media_category' )

    https://codex.wordpress.org/Function_Reference/get_the_terms

    Thanks
    E

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Getting taxonomy values from image’ is closed to new replies.