WordPress getFeaturedImage

I have a real-estate website in wordpress.

Under each listed property is displayed a corresponding agent. Everything works fine, but the problem is that i want that agent’s featured image to be displayed as well.

Read More

Here is the code for displaying the agent under each property

<?php
//// CHECKS TO SEE IF WE HAVE ANY GENTS ASSIGNED TO THIS PROPERTY
if(get_post_meta(get_the_ID(), 'agents', true) != '' || ddp('public_submissions') == 'on') :

?>

<div id="property-agents">
    <h2><?php _e('Contact Agent', 'btoa'); ?></h2>        
    <ul class="list-agents">       
        <?php
            //// LETS LOOP OUR AGENTS
            $agents = get_post_meta(get_the_ID(), 'agents', true);

            //// IF WE HAVE AN ARRAY
            if(is_array($agents)) :
            foreach($agents as $agent) :

                $this_agent = '';

                //// IF IT'S A POST TYPE
                if($this_agent = get_post($agent)) {

                    if($this_agent->post_type == 'agent') {
                        $name = $this_agent->post_title;
                        $position = get_post_meta($this_agent->ID, 'position', true);
                        $email = get_post_meta($this_agent->ID, 'email', true);
                        $phone = get_post_meta($this_agent->ID, 'phone', true);

                    } else { $this_agent = 'user'; }

                } else { $this_agent = 'user'; }

                if($this_agent == '' || $this_agent == 'user') {

                    if($this_agent = get_user_by('id', $agent)) {

                        $name = $this_agent->display_name;
                        $position = esc_attr( get_the_author_meta( 'position', $this_agent->ID ) );
                        $email = $this_agent->user_email;
                        $phone = get_the_author_meta( 'phone', $this_agent->ID );

                    }

                }

                //// IF WE HAVE GOTTEN THE USERS NAME
                if($name) :

        ?>

            <li>

                <div class="two-fifths">

                    <h4><?php echo $name; ?></h4>
                    <h5><?php echo $position; ?></h5>

                </div>
                <!-- /.two-fifths/ -->

                <div class="three-fifths last">

                    <?php if($email != '') : ?><div class="three-fifths"><strong><?php _e('Email', 'btoa'); ?></strong><a href="mailto:<?php echo $email; ?>" title="Email John"><?php echo $email; ?></a></div><?php endif; ?>

                    <?php if($phone != '') : ?><div class="two-fifths last"><strong><?php _e('Phone', 'btoa'); ?></strong><?php echo $phone; ?></div><?php endif; ?>

                </div>
                <!-- /.three-fifths/ -->

            </li>

        <?php endif; endforeach; endif; ?>

    </ul>

</div>
<!-- /#property-agents/ --> 

and this is the code for gettin the featured image

function ddTimthumb($img = NULL, $width = NULL, $height = NULL) {

    //// IF AN imAGE HAS BEEN PROVIDED
    if($img != NULL) {

        $image = vt_resize('', $img, $width, $height, true );

        //// IF ITS NOT AN ERROR
        if(is_array($image)) { return $image['url']; } else { return ''; }

    } else { return ''; }

}

function getFeaturedImage($post_id = NULL) {

    if($post_id != NULL) {

        $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'single-post-thumbnail' );
        return $image;

    }

}

Related posts

Leave a Reply

1 comment