I have a problem and I believe the answer lies here: https://www.advancedcustomfields.com/resources/get-values-from-a-taxonomy-term/ But I cant figure out how to apply it to my code...
I have used Advanced Custom Fields to add an image field inside the categories of a custom post type. My custom post type is call Short Courses, and the category name is Course Types.
Here's the loop:
<?php
$customPostTaxonomies = get_object_taxonomies('short_courses');
if(count($customPostTaxonomies) > 0)
{
foreach($customPostTaxonomies as $tax)
{
$args = array(
'orderby' => 'name',
'show_count' => 0,
'pad_counts' => 0,
'hierarchical' => 1,
'taxonomy' => $tax,
'title_li' => '',
'hide_empty' => FALSE
);
$categories = get_categories( $args );
foreach ( $categories as $category ) {
echo '
<div class="one-half sc-cat-items">
<img src="' . get_field('course_type_image', $category->name) . '">
<h2>
<a href="' . get_category_link( $category->term_id ) . '">' . $category->name . '</a>
</h2>
</div>';
}
}
}
?>
I've tried to add this line in to retrieve the image for each category:
<img src="' . get_field('course_type_image', $category->name) . '">
This prints out the <img src="">
tag, but it isn't filling in the URL for some reason...
Ive also tried: <img src="' . get_field('course_type_image') . '">
on it's own, but the same result
Currently it looks like this:
and I'm trying to display the image for each category so it looks like this: