0

I have a custom post type 'kalender' with custom taxonomy 'type-evenement' and the taxonomy has a custom field (image) to load a tumbnail.

I want to load the image of this taxonomy on the page of my posts with a custom shortcode and php. Only the image will not display.

The shortcode is working because i can get the title en description of the taxonomy but not the image. This is my code that i put in the fuction.php:

function custom_elementor_term_information( $atts) {
    $post_id = get_the_ID();
    $taxonomies = get_post_taxonomies($post_id);

    if ($taxonomies) {
        foreach ($taxonomies as $taxonomy) {
            $terms = get_the_terms($post_id, $taxonomy);

            if ($terms && !is_wp_error($terms)) {
                echo '<div class="taxonomy">';
                echo '<h2>' . $taxonomy . '</h2>';

                foreach ($terms as $term) {
                    echo '<div class="term">';
                    echo '<h3>' . $term->name . '</h3>';
                    echo '<p>' . $term->description . '</p>';
                    
                    // Display the term image
                    $image = get_field('thumbnail', $taxonomy . '_' . $term->term_id);
                    if ($image) {
                        echo '<img src="' . $image['url'] . '" alt="Term Thumbnail">';
                    }

                    echo '</div>';
                }

                echo '</div>';
            }
        }
    } else {
        echo '<p>No taxonomies found for the post.</p>';
    }
}
add_shortcode( 'custom_elementor_term_information', 'custom_elementor_term_information');

What do i wrong?

i tried to change the output of the custum image field from array to url or post id. Nothing works.

The image will not show or load and everything else from the taxonomy is good. help please

0 Answers0