add custom fields ACF to a Taxonomy Term

Question

i need to costumise tag names and category names in the category.php pages, using ACF :
This is my code it’s refered to this link :
https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/

 <?php
// get the current taxonomy term
$term = get_queried_object();
// vars
$color1 = get_field('color-categorie', $term);

?>
<div>
<div class="category-class" style="background-color:<?php echo $color1; ?>;">
<?php

$categories = get_the_category();
 
if ( ! empty( $categories ) ) {
    echo esc_html( $categories[0]->name );   
}

?>
</div>
 </div>
<?php
// get the current taxonomy term
$term2 = wp_get_post_tags();
// vars
$image1 = get_field('icon-tag1', $term2);
$image2 = get_field('icon-tag2', $term2);
$color2 = get_field('color-tag', $term2);
?>

<div>
  <div class="tag-class"  style="background-color:<?php echo $color2; ?>">
<?php

$posttags = get_the_tags();
if ($posttags) {
  foreach($posttags as $tag) {
    echo $tag->name . ' '; 
  }
}
?>


            <img src="<?php echo $image1; ?>" class="icone-tag">
            <img src="<?php echo $image2; ?>" class="icone-tag">


</div></div>

The result is good on Category , but don’t work on Tags ???
I know that the get_queried_object(); is applayed on teh category , but not on tags!, I have tru it with: wp_get_post_tags or wp_get_tags, but withous success !!!
Thx for your help

0
tarek temimi 2 years 2020-08-25T08:10:21-05:00 0 Answers 34 views 0

Leave an answer

Browse
Browse