Hello,
I have custom field (image) in my categories.
I would like to display this image in its child articles.
I already read this post which seems reply the same question :
https://support.advancedcustomfields.com/forums/topic/get-image-from-category-custom-field/
But it displays ALL the categories images in my article, and not only the parent category 🙁
Do I need to adapt something in this code ?
Thanks in advance for your help 🙂
Hello there!
I wrote a tutorial on my blog about that:
https://www.pushaune.com/blog/tutoriels/comment-recuperer-un-champ-acf-dune-categorie/
If you don’t speak french, here is the answer:
<?php $terms = get_the_terms( get_the_ID(), 'category');
if( !empty($terms) ) {
$term = array_pop($terms);
$custom_field = get_field('image_de_fond_de_categorie', $term );
$custom_field_text = get_field('texte_dintroduction', $term );
?>
<img src="<?php echo $custom_field; ?>"><!-- Afficher l'image de la catégorie -->
<?php echo $custom_field_text; ?><!-- Afficher le texte de la catégorie -->
<?php } ?>
C’est parfait merci beaucoup ! 🙂