Display Advanced Custom Fields Attachment or Image on a Category

If you ever need to use Advanced Custom Fields to load an image or attachment on a category, here’s the template code you need. 🙂

// vars
$queried_object = get_queried_object(); 
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;  
// load thumbnail for this taxonomy term (term object)
$thumbnail = get_field('thumbnail', $queried_object);
// load thumbnail for this taxonomy term (term string)
$thumbnail = get_field('thumbnail', $taxonomy . '_' . $term_id);
the_field( $thumbnail );
Posted in

Toby Cryns

Toby Cryns is a freelance CTO, expert WordPress developer, and teacher.

He offers free advice to improve your freelance biz.

He also publishes small droppings every now and them to https://twitter.com/tobycryns and https://twitter.com/themightymo.com

Follow Toby's contributions on Github and WP.org.