0

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 );
var_dump($category_image);

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

Thanks in advanced!

1 Answer 1

2

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 );
2
  • I don't have enough reputation to UP this but thanks dude, been stuck on this for a few good hours... Jan 4, 2017 at 16:25
  • That's alright. I think you should be able to mark it as accepted answer, though. Good luck!.
    – socki03
    Jan 4, 2017 at 16:26

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