I've got a function to display all images in the media library on a page. I would like to display the date of each image, but using get_the_date() only returns today's date.
Here is the code I'm using:
function get_images_from_media_library() {
$args = array(
'post_type' => 'attachment',
'post_mime_type' =>'image',
'post_status' => 'inherit',
'order' => 'DESC'
);
$query_images = new WP_Query( $args );
$images = array();
foreach ( $query_images->posts as $image) {
$images[]= $image->guid;
}
return $images;
}
function display_images_from_media_library() {
$imgs = get_images_from_media_library();
$html = '<div id="media-gallery">';
foreach($imgs as $img) {
$html .= '<img src="' . $img . '" alt="" />';
echo get_the_date('F j, Y');
}
$html .= '</div>';
return $html;
}
I could someone show me where I'm going wrong?
wp_query()
object, you might want it to also runwp_reset_query()
at the end so it doesn't mess up other loops.