Here’s another snippet of code I had to trawl through hundreds o posts to get working, while dealing with Custom Post Types and their associated Taxonomies, you may want to also add an image and also use the default Category/Taxonomy Description alongside it, below is the code to allow you to do exactly that, the one thing to make sure is to set up your custom field rules correctly.
First create a Image custom field within ACF with a Return Value of ‘Array’ an then in order for the Meta Box to display you must select the following within the ‘Location’ Meta Box.
Select ‘Taxonomy Term’ from within the ‘Show this field if’ selection menu, also select ‘is equal to’ and then select the appropriate Category or Taxonomy.
Once this is setup the Meta Box show appear within your Categories & Taxonomies. The code below will render your Categories/Taxonomies by each term within a List Item which includes a link to that specific Category/Taxonomy Archive, the image you’ve uploaded and the main Category & Taxonomy Description.
<?php
$terms = get_terms( 'your_taxonomy_term' );
echo '<ul>';
foreach ( $terms as $term ) {
// The $term is an object, so we don't need to specify the $taxonomy.
$term_link = get_term_link( $term );
// Taxonomy Image - ACF.
$term_image = get_field('your_taxonomy_image_field', $term);
$size = 'thumbnail'; // (thumbnail, medium, large, full or custom size) by I.D in ACF
if ( $term_image ) {
$icon = wp_get_attachment_image( $term_image, $size );
}
// If there was an error, continue to the next term.
if ( is_wp_error( $term_link ) ) {
continue;
}
// We successfully got a link. Print it out.
echo '<li class="' . $term->slug . '">';
if ( $term_image ) {
echo '<a href="' . esc_url( $term_link ) . '" title="' . $term->name . ' Events">'. $icon .'</a>';
}
echo '<span>';
echo '<a class="term-link" href="' . esc_url( $term_link ) . '">';
echo '<h4>' . $term->name . '</h4>';
echo '</a>';
echo '<p>'. $term->description .'</p>';
echo '</span>';
echo '<li>';
}
echo '</ul>';
?>
You can achieve this task in various ways within WordPress but Advanced Custom Fields makes the task a lot less stressful and most importantly more user friendly for your client.