• Resolved TheBusinessCat

    (@thebusinesscat)


    Hi there,

    Thank you for the great plug-in.

    I have created a CPT name Property Listings. I have also created a taxonomy called Estate Agent. I have added a custom field to the taxonomy to enable an image to be uploaded of the agent.

    I am using the Divi Theme and page builder. I have created a template for the individual property listings page using the Divi Theme Builder. I am trying to get the custom field image from the taxonmy to display on the individual page for the property listing, and have tried to write my own custom shortcode after doing some research. Below is my code:

    function dg_estate_agents() {
        global $post;
        $string = '<div>';
        $estateAgent = wp_get_post_terms($post->ID, 'estate-agent');
    
        if (!empty($estateAgent)) {
            foreach ($estateAgent as $item) {
                $image = get_field('estate_agent_image', 'estate_agent_image_'.$item->term_id);
                $imgurl = '';
    
                if (!empty($image) && isset($image['url'])) {
                    $imgurl = $image['url'];
                }
    
                $string .= '<div>';
                $string .= '<img class="dg-estate-agent-img" src="' . $imgurl . '" alt="' . $item->name . '" />';
                $string .= '</div>';
            }
        }
        $string .= '</div>';
    
        return $string;
    }
    add_shortcode('estate_agents_info', 'dg_estate_agents');

    For some reason the img tag pulls through but not the src. Here is a link to a screenshot.

    Please can you let me know if I need to amend my code?

    Thanking you in advance.

Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Divi Theme Builder & Taxonomy Image’ is closed to new replies.