This has probably been answered before but I'm stumped so I'll ask anyway.

I have a custom post type called products. I then have a custom taxonomy called product-category. I've set up a custom field with the Advanced Custom Fields plugin on the product categories called featured_image. I've got a shortcode controlled function where the user supplies the slug like this [ProductCategory product-category-slug] and I want it to return the featured_image. This is the function I have:

function getProductCategory($cat){
    $product_category = get_terms( 'product-category', array( 'slug' => $cat ) );
    $name = $product_category[0]->name;
    $image = $product_category[0]->get_field('featured_image');
    $return = $image;

    return $return;
add_shortcode( 'ProductCategory', 'getProductCategory' );
add_filter('ProductCategory', 'do_shortcode');

This function is successfully retrieving the category, and I return the name is displays correctly. Now the problem is, I can't use get_field() in this way. How do I get the custom field?


1 Answer 1


If you'r using ACF plugin you should look the documentation first, here's relevant

ACF saves taxonomies terms meta to options table, and they can be accesed using get_field( "{$field_key}", "{$term->taxonomy}_{$term->term_id}" );

So in you'r example it would be:

$image = get_field( 'featured_image', 'product-category_' . $product_category[0]->term_id );

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