Home › Forums › General Issues › Display featured images of selected taxonomy terms
I created:
I added:
Now I would like to show the featured images of the taxonomy terms I selected for a particular course. Tried the code below, but this code shows the featured images of all taxonomy terms, not only the ones I selected for the particular course.
function custom_accreditation_logo () {
ob_start();
$terms = get_terms( array( 'taxonomy' => 'accreditations', 'hide_empty' => false ) );
foreach ( $terms as $term ) {
$image = get_field('featured_image', 'accreditations_' . $term->term_id );
echo '<img src="' . $image['url'] . '" alt="' . $image['alt'] .'">';
}
$content = ob_get_clean(); // store buffered output content.
return $content;
}
add_shortcode( 'accreditatie_logos', 'custom_accreditation_logo' );
Does anyone know how to only show the featured images of the selected taxonomy terms (not the unselected ones)?
I came up with the following solution:
function custom_accreditation_logo () {
ob_start();
$queried_object = get_queried_object();
$post_id = $queried_object->ID;
$terms = wp_get_post_terms( $post_id, 'accreditations' );
//$terms = get_terms( array( 'taxonomy' => 'accreditations', 'hide_empty' => false ) );
echo '<div class="acc_logos">';
foreach ( $terms as $term ) {
$image = get_field('featured_image', 'accreditations_' . $term->term_id );
echo '<img src="' . $image['url'] . '" alt="' . $image['alt'] .'">';
}
echo '</div>';
$content = ob_get_clean(); // store buffered output content.
return $content;
}
add_shortcode( 'accreditatie_logos', 'custom_accreditation_logo' );
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.