Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the function got get all the media files wordpress?

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

like image 697
user75472 Avatar asked Jul 22 '10 09:07

user75472


People also ask

Can I download all media from WordPress?

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.

How do I get all images on WordPress?

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!

What is media file in WordPress?

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.


1 Answers

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.

like image 64
Matt Gibson Avatar answered Oct 06 '22 08:10

Matt Gibson