Support

Account

Home Forums General Issues Display custom field (image) from parent category Reply To: Display custom field (image) from parent category

  • 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 } ?>