Skip to content

Instantly share code, notes, and snippets.

@twentyfortysix
Last active February 13, 2016 19:51
Show Gist options
  • Save twentyfortysix/5145042 to your computer and use it in GitHub Desktop.
Save twentyfortysix/5145042 to your computer and use it in GitHub Desktop.
WP - get post images
<?php global $post;
$g_args =array(
'post_parent' => $post->ID,
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_mime_type' => 'image',
'order' => 'ASC',
'orderby' => 'menu_order'
);
$attachments = get_children($g_args);
//~ process all found
foreach($attachments as $key => $val) {
if(!empty($val->ID)){
$img_obj = wp_get_attachment_image_src( $val->ID, 'thumbnail');
$url = $img_obj[0];
echo '<img src="'.$url.'" title="'.$the_title.'" alt="'.$val->post_title.'" />';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment