Get Image Src for All Images on a Post in WordPress

Get the image src for all images attached to a post.

The PHP function returns an array of image URLs:

function get_all_image_src_by_post_id($post_id)
{
    $photos = get_children( array('post_parent' => $post_id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order') );
    $array = array();
    if($photos) 
    {
        foreach($photos as $photo) 
        {
            $image_attributes = array();
            $image_attributes = wp_get_attachment_image_src ( $photo->ID, 'full' ) ;
            $array[] = $image_attributes[0];
        }
    }
    return $array;
}

More Related Posts