I’m trying to get the featured image from the postid passed through the url.
http://www.example.com/schedule-appointment/?postid=589
I’ve managed to get the postid from the url, but everything goes down hill from there. I must be missing something simple. I’m not a programmer…would love some help.
add_shortcode('CF7_ADD_POST_ID', 'cf7_add_post_id');
function cf7_add_post_id(){
$Path=$_SERVER['REQUEST_URI'];
$control = array();
$control = explode('?', $Path);
$get = $control[1];
$get = explode('=', $get);
$get2 = $get[1];
$args = array(
'post_type' => 'page',
'post__in' => $get2,
);
// Fire up the Query
$the_query = new WP_Query( $args );
while ( $the_query->have_posts() ): $the_query->the_post();
$feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->$get2) );
echo '$feat_image';
};
Try this
There is no need for the WP_Query , You have one id and you can easily get this done by using following code,
};