WordPress show custom field image in thumbnail or custom size

When we use custom image field in custom post type, we need to show these images in custom size like thumbnail,medium or any size inside wp loop. Find below code ,you can use this code inside wp loop to show the image in your custom size.

<?php
				
				$image_url=get_post_meta($post->ID,'wpcf-photo',true);
				
				$attachment = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE guid = '$image_url'"  );
				$attachment_id = $attachment->ID;

				//echo "AID".$attachment_id;
  
 		 		 echo wp_get_attachment_image($attachment_id,'thumbnail');
				?>
			 

in above code ‘wpcf-photo’ is the custom field name and ‘thumbnail’ is wordpress default size ,You can mention your custom size name that should already declared in theme.
Visit our WordPress Video tutorials and Advance WordPress Training .