Get image from post’s gallery

Is there any possibility on WordPress to get an image from a post gallery?
Images are not inserted in the post, are on it’s gallery.
I’m trying to do a “galleries index” page and instead having the user set a “cover image” I’d like to take any of the attached to the post as part of a gallery.

I tried the wp_get_attachment_image() with no luck, I think because it works for inserted images, not the ones on it’s gallery.

Read More

Thanks in advance.

Juan.-

Related posts

Leave a Reply

2 comments

  1. You can get the attached media to a post using get_children. IE: get the first attached image for post ID == 14

    $args = array( 'post_mime_type' => 'image',
                   'numberposts'    => 1,
                   'post_parent'    => 14,
                   'post_type'      => 'attachment' );
    
    $first_attached_image = get_children( $args );