I have the following snippet of code, basically I get the set value of id from the metabox, get the current id based on the loop, try and match, if htey match I want to pull the values from the matched id, currently i can only get the id, but i would like to get the associated custom field values of that post as well.
Also I don't know why, even if it matches the value, it will still echo out the else statement twice, i guess cause it's in the while loops, but how do i get ride of that?
<?php
$list_agent = get_post_meta( $post->ID,'ec_agents',true );
$args = array( 'post_type' => 'agent_type');
$the_query = new WP_Query( $args );
$id = $post->ID;
while ( $the_query->have_posts() ) : $the_query->the_post();
if ($id == $list_agent) {
echo "success";
the_title();
//Both Meta values not showing
echo get_post_meta( $post->ID,'_agent_phone',true );
echo get_post_meta( $post->ID,'_agent_email',true );
} else {
echo "better luck next time";
}
endwhile;
wp_reset_postdata();
?>