I've a problem with Advanced Custom Fields Plugin

I create a custom field named: bgcolor

I want to print the value in category.php, this is my code:

$color = get_field('bgcolor', 'category_'.the_category_ID( $echo ).'');
echo $color;

What its wrong?


closed as off-topic by Milo, Pieter Goosen, cybmeta, Robert hue, Mayeenul Islam Feb 11 '15 at 16:31

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.


I assume you want the field for the current category archive, not the category of the post inside the loop? Try get_queried_object_id() instead of the_category_ID( $echo ).

In single.php, you just need a slightly different iteration of your original attempt:

if ( $terms = get_the_category() )
    the_field( 'bgcolor', 'category_' . $terms[0]->term_id );
  • Its posible print the value in category.php and single.php? – Ferrrmolina Feb 10 '15 at 12:53
  • 1
    See my revision. – TheDeadMedic Feb 10 '15 at 13:37
  • Can you help me again? How print data, for example: in loop index.php? – Ferrrmolina Feb 11 '15 at 9:58
  • Just use my snippet inside your while ( have_posts() ) loop - it will work for each post. – TheDeadMedic Feb 11 '15 at 10:05
  • Can you help me with a ternary operator? I want to show a list of my categories in index page, i must use a ternary operators to display the field: pastebin.com/K8wxka0W This code, return a blank div :/ – Ferrrmolina Feb 11 '15 at 10:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.