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


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:


$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) {
        the_attachment_link($post->ID, false);


...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.

            <?php if ( have_posts() ) : while ( have_posts() ) : the_post();    

                    $args = array(
                        'post_type' => 'attachment',
                        'numberposts' => -1,
                        'post_status' => null,
                        'post_parent' => $post->ID

                    $attachments = get_posts( $args );
                    if ( $attachments ) {
                        foreach ( $attachments as $attachment ) {
                            echo '<li>';
                            echo wp_get_attachment_image( $attachment->ID, 'full' );
                            echo '<p>';
                            echo apply_filters( 'the_title', $attachment->post_title );
                            echo '</p></li>';

            endwhile; endif; ?>

Need Your Help

unable to use a "degree" symbol in xml

java xml symbols

I don't know why but I'm unable to use a "degree" symbol (°) with xml Text. I tried with &deg;

Best explanation for languages without null

programming-languages functional-programming null nullpointerexception non-nullable

Every so often when programmers are complaining about null errors/exceptions someone asks what we do without null.