Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save developer-anuragsingh/d55ce444a6e549e24ee5 to your computer and use it in GitHub Desktop.
Save developer-anuragsingh/d55ce444a6e549e24ee5 to your computer and use it in GitHub Desktop.
<?php $myMetaFields = get_post_meta($post->ID, 'YOUR_META_KEY', true);
foreach($myMetaFields as $singleFiled) {
$attachmentId = $singleFiled['icon'];
$attachmentUrl = wp_get_attachment_image_src( $attachmentId, 'full' );
$src = $attachmentUrl[0];
$attachmentMetaData = wp_get_attachment_metadata($attachmentId);
$attachmentWidth = $attachmentMetaData['width'];
$attachmentHeight = $attachmentMetaData['height'];
$attachmentFileURL = $attachmentMetaData['file'];
// attachments are one of the wordpress built-in 'Post Type'
$imgMeta = get_post($attachmentId); // Retrieves post data by given a post ID
$imgTitle = $imgMeta->post_title;
$imgCaption = $imgMeta->post_excerpt;
$imgDescription = $imgMeta->post_content;
$imgAltTag = get_post_meta($attachmentId, '_wp_attachment_image_alt', true); // Through WP built-in function
#echo $imgAltTag. '<br>'; ?>
<img src="<?php echo $src; ?>">
<?php
}?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment