Skip to content

Instantly share code, notes, and snippets.

@hectorlorenzo
Created January 29, 2014 06:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hectorlorenzo/8683108 to your computer and use it in GitHub Desktop.
Save hectorlorenzo/8683108 to your computer and use it in GitHub Desktop.
Simple Wordpress function to get the attached images that belong to a specific post.
// get all attachments from a post, except the featured image
function get_attached_images ( $post_ID, $featured_image = false ) {
$args = array(
'post_type' => 'attachment',
'posts_per_page' => -1,
'post_parent' => $post_ID
);
// do we want the featured image?
if (!$featured_image) {
$args['post__not_in'] = array(get_post_thumbnail_id( $post_ID ));
}
$att_images = get_posts( $args );
return $att_images;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment