Wordpress:使用the_post_thumbnail()获取自定义字段图像

I use the custom field photo to upload an image. In the frontend I get its URL with this code:

$imgid=get_post_meta($post->ID, 'photo', true);
$img=wp_get_attachment_image_src($imgid);
$imgurl=$img[0];

Now I want to show it using the standard WP sizes (thumbnail, medium, ...) of the_post_thumbnail().

I've tried some solutions that don't work:

the_post_thumbnail('medium', array('src' => $imgurl));

or

the_post_thumbnail('medium', $img);

Any ideas?

Just pass the size as the second argument of wp_get_attachment_image_src(), like so:

$imgid = get_post_meta($post->ID, 'photo', true);
$img = wp_get_attachment_image_src( $imgid, 'thumbnail' );
$imgurl = $img[0];