mistercyril, what is value of your custom field 'bg_images', is it a field with a single value or field with multiple values? How did you created this custom field?
This is how I made it. I use meta-box (https://github.com/rilwis/meta-box) plugin where uploaded images ID's are saved as a field with multiple values. So first I need to check all values from array, then reset array and get only first value. Further, each uploaded image is treated as an attachment so I need to use wp built-in function to get image URL.
here is my code:
global $post;
$post_id = get_post_custom($post->ID);
$slide_bg_array = get_post_meta($post->ID, "custom_meta_slide_bgimg", false);
global $wpdb;
if ( !is_array( $slide_bg_array ) )
$slide_bg_array = ( array ) $slide_bg_array ;
if ( !empty( $slide_bg_array ) ) {
$slide_bg_array = implode( ',', $slide_bg_array );
$images = $wpdb->get_col( "
SELECT ID FROM $wpdb->posts
WHERE post_type = 'attachment'
AND ID IN ( $slide_bg_array )
ORDER BY menu_order ASC
" );
$image = reset($images);
} else {
$image = "";
}
$imgsrc = wp_get_attachment_image_src( $image, 'full' );
$imgsrc = $imgsrc[0];
$slide_bgimg = "url(". $imgsrc .")";
And later I changed output. As you can see I use many other custom fields and everything works great.
$output .= "<div style='background-image:" . $slide_bgimg . "; background-color:" . $slide_bgcolor . "; width: 100%; height: 100%;' class='content clearfix'>" ;
$output .= do_shortcode($content) ;
$output .= "<h1 class='entry-title-slider1 slide_1'><a href=". $blaurl ." >" . $bio . "</a></h1>";
$output .= "<div class='post-category slide_2'>" .$field_1. $field_2. "</div>";
$output .= "</div>";
Hope this helps.