Support

Account

Home Forums General Issues Display featured images of selected taxonomy terms Reply To: Display featured images of selected taxonomy terms

  • 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' );