Is it possible to retreive media image directly into the library... Something like get_media ('all') and it return a array with image url, caption, description etc etc..
1 Answer
Here you go:
function get_media_all_wpa14177(){
$args = array(
'post_type' => 'attachment',
'post_mime_type' =>'image',
'post_status' => 'inherit',
'posts_per_page' => -1,
);
$query_images = new WP_Query( $args );
$images = array();
foreach ( $query_images->posts as $image) {
$images[]= $image->guid;
}
return $images;
}
Usage:
$Images = get_media_all_wpa14177();
-
3The
guid
is not guaranteed to always point to an existing file, it's better to return the attachment post IDs and then use the specific functions, likewp_get_attachment_metadata
. Apr 7, 2011 at 18:25