Home Forums Front-end Issues Not getting color for category labels using custom taxonomy


Not getting color for category labels using custom taxonomy

  • I have tried to implement this

    This is my current code wich returns no color whatsoever.

    $queried_object = get_queried_object();
    $taxonomy = $queried_object->taxonomy;				
    $term_id = $queried_object->term_id;  
    $color = get_field('color_de_fondo_categoria_tienda', $taxonomy . '_' . $term_id);	
    $cat_array = ( get_the_terms( get_the_ID(), 'categorias_tienda') );
    	foreach ( $cat_array as $cat  ) {
            if($cat->name != 'Destacados') { // the term ID you want to exclude
                echo '<li style="color:' . $color .';">' . $cat->name . '</li>';

    do note it is in a regular page template such as “index”.

  • What you are trying to do will only work on a term archive page.

    If index.php is showing the main archive, this is not a term archive and get_queried_object() is returning an object of “Post_Type”

    You would need to get the field from the category inside of your loop over the categories using $cat->term_id from your example code.

  • Excellent works perfectly, thank you so much!!!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.