Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get ALL images from a post, INCLUDING featured and gallery images.
<?php
$attachments = get_children(array(
'post_parent' => $post->ID,
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_mime_type' => 'image',
'order' => 'ASC'
));
$i = 0;
foreach($attachments as $att_id => $attachment) {
$full_img_url = wp_get_attachment_url($attachment->ID);
if ( $i > 0 && $i < 5 ) {
echo '<img src="' . $full_img_url . '" alt="">';
}
$i++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment