List All Files From Media Library
If you want to list all files from your media library, you can use this snippet:
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => null,
);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $post) {
setup_postdata($post);
the_title();
the_attachment_link($post->ID, false);
the_excerpt();
}
}
wp_reset_postdata();
If you want to list only images, add ‘post_mime_type’ => ‘image’ to $args.