I created an image field and attached it to my CPT custom taxonomy. This part is working fine. The image field shows up in the backend dashboard.
I’m trying to query the custom taxonomy to show the top level categories with images.
Here is my function:
function rt_product_categories() {
$productcategories = get_terms(
array(
'taxonomy' => 'product_category',
'parent' => 0,
)
);
if ( !empty( $productcategories ) && ! is_wp_error( $productcategories )) {
$productcats = '<div class="aeroProducts">';
foreach ($productcategories as $category) :
$productcats .= '<div class="productEntry"><a href="'.esc_url( get_term_link( $category ) ).'">';
$productcats .= '<h3>'.$category->name.'</h3>';
if ( get_field('product_category_img', $category->term_id ) ) $productcats .= "there is a photo";
$productcats .= '</a></div>';
endforeach;
$productcats .= '</div>';
// Code
return $productcats;
} else { //end if posts
return 'no categories available';
}
}
I can’t seem to figure out how to check (and then display) the image. I’m sure I’m missing something. Any ideas what it is?
use
get_field('product_category_img', 'term_'.$category->term_id )
or
get_field('product_category_img', $category)
or you can also use
get_field('product_category_img', 'product_category_'.$category->term_id )
Hey thanks, My issue has resolved..