Hi.
I have researched through different websites and read all the ACF documentation but it seems that it does not work for me.
I’m trying to create a list of categories with its respective featured image that I added using ACF, but it never shows me anything.
What I have done so far:
I created a custom content type with UI CPT
I created the taxonomy “furnitures_type” and with ACF I added an image field called “tax_main_image”.
Now, I have a Post Type with several “furnitures_type” categories added and on that page I want to show the category list with its main photo.
I tried with this code:
<?php
$terms = get_field('tax_main_image');
if( $terms ): ?>
<ul>
<?php foreach( $terms as $term ): ?>
<h2><?php echo $term->name; ?></h2>
<p><?php echo $term->description; ?></p>
<a href="<?php echo get_term_link( $term ); ?>">View all '<?php echo $term->name; ?>' posts</a>
<?php endforeach; ?>
</ul>
<?php endif; ?>
Please, I need help
I believe you need to add the wordpress loop.
Hi Rociopts. thank you very much. I could solve it I leave the code for other people who can not find a solution.
<div class="lista-taxonomia">
<?php $types = get_terms( array( 'taxonomy' => 'nombre-de-la-taxonomia', 'hide_empty' => true, ) );
foreach($types as $type) { ?>
<div class="otra-div">
<?php $image = get_field('nombre-del-campo-de-imagen', 'nombre-de-la-taxonomia_' . $type->term_id . '' );
if ( has_term( $type->term_id, 'nombre-de-la-taxonomia')) {
echo '<img class="imagenes" src="' . $image['url'] . '" /> ' . '<p>'. $type->name . '</p>';
} ?> </div> <?php } ?>
</div>