Can anyone suggest me what is the function to get all the images stored for wordpress? I just need to list all the images seen under menu Media of the wordpress admin.
Thanks in advance
The first thing you need to do is install and activate the Export Media Library plugin. For more details, see our guide on how to install a WordPress plugin. In the Folder Structure dropdown menu, you can choose 'Single folder with all files,' which means all of your media will be downloaded into one folder.
If you just want to get images, as TheDeadMedic commented, you can filter with 'post_mime_type' => 'image' in the arguments. Yup, you can just use 'post_mime_type' => 'image' in your $args , and WordPress will cleverly match that against all image mime types :) @TheDeadMedic Good to know!
Media is a tab in your WordPress admin sidebar which is used to manage user uploads (images, audio, video, and other files). Under the Media menu, there are two screens. The first screen Library lists all the files in the media library. These files can be edited and deleted from the library.
Uploaded images are stored as posts with the type "attachment"; use get_posts() with the right parameters. In the Codex entry for get_posts(), this example:
<?php
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => null, // any parent
);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $post) {
setup_postdata($post);
the_title();
the_attachment_link($post->ID, false);
the_excerpt();
}
}
?>
...loops through all the attachments and displays them.
If you just want to get images, as TheDeadMedic commented, you can filter with 'post_mime_type' => 'image'
in the arguments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With