Depends on the version of WP you are using.
My function for that looks like the following:
//get the post attachments
$attachments = get_children($att_array);
//make sure there are attachments
if (is_array($attachments)){
//loop through them
foreach($attachments as $att){
//find the one we want based on its characteristics
if ( $att->menu_order == 0){
$image_src_array = wp_get_attachment_image_src($att->ID, $size);
//get url - 0 - url; 1 and 2 are the x and y dimensions
$url = $image_src_array[0];
$caption = $att->post_excerpt;
}
}
}
If you check ioni2 you would see it in action
I am using the latest virsion 2.8.
and that did not work, it says missing files.
i went back and used the content to make sure the files are there, and they are.