Skip to content

Instantly share code, notes, and snippets.

@mlbd
Last active January 3, 2016 07:38
Show Gist options
  • Save mlbd/2650ab41a12dfe5144cc to your computer and use it in GitHub Desktop.
Save mlbd/2650ab41a12dfe5144cc to your computer and use it in GitHub Desktop.
// get data form post meta
$dataMeta = get_post_meta( get_the_ID(), 'my-metafield', true );
// make sure your post meta isn't empty
if(!empty($dataMeta)) {
// image url
$image_url = $dataMeta;
// retrive attachment ID
$id = wplap_get_attachment_id_from_url($image_url);
// retrieve the size of yur image that you want to set
$image_thumb = wp_get_attachment_image_src($id, 'custom-thumb' );
// display the image url with size
echo $image_thumb[0].'<br />';
// display as a image with size
echo '<img src="'.$image_thumb[0].'" width="'.$image_thumb[1].'" height="'.$image_thumb[2].'" />';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment