Skip to content

Instantly share code, notes, and snippets.

@mrfoxtalbot
Last active March 16, 2018 11:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrfoxtalbot/33cc3173de59d2e7f3b26c0b0a7968b0 to your computer and use it in GitHub Desktop.
Save mrfoxtalbot/33cc3173de59d2e7f3b26c0b0a7968b0 to your computer and use it in GitHub Desktop.
Use ACF to list term icons/images in a custom WordPress taxonomy
<?php
// load all 'category' terms for the post
$terms = get_the_terms( get_the_ID(), 'nombre_taxonomia');
foreach ( $terms as $term ) {
echo ' <div class="tax-icons">';
// we will use the first term to load ACF data from
if( !empty($terms) ) {
$term = array_pop($terms);
$custom_field = get_field('nombre_campo_icono', $term );
echo '<img src="';
echo $custom_field;
echo ' ">';
}
echo '<div class="tax-name">';
echo $term->name;
echo '</div>';
echo '</div>';
} ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment