I have created an image custom field using ACF which will be used as a featured image for each category. What I can't figure out is how to take that information and display it as a background image.

$category = get_the_category();
$category_id = $category[0]->term_id;

$category_image = get_field( 'featured_image', $category_id );

I have used the ACF documentation to write the above but this is displayed as "NULL".

Thanks in advanced!

closed as off-topic by Mark Kaplun, fuxia Jan 4 '17 at 16:52

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.


To retrieve things out of a category, it's not quite as easy as passing just the category ID.

All taxonomies use the same layout: '{taxname}_{term_id}'

So, your example would be

$category_image = get_field( 'featured_image', 'category_' . $category_id );
  • I don't have enough reputation to UP this but thanks dude, been stuck on this for a few good hours... – Dragos Micu Jan 4 '17 at 16:25
  • That's alright. I think you should be able to mark it as accepted answer, though. Good luck!. – socki03 Jan 4 '17 at 16:26

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