How can I list URLs of all audio files within my media gallery?

Welcome to WPSE marctain!

Edit
There are some critiques on using the guid but no one of the commentators managed to edit this answer to a better one, so I’ll do it.

Yes, using guid is a bad idea in the long run, I knew that and I should have pointed that out, I didn’t, it was a mistake. I’m sorry, it was a quick and dirty answer.

In my original answer, I would have made usage of wp_get_attachment_url to get the correct url in any case. This adds an extra query, but it is safe to use.

$args = array
    (
        'post_type' => 'attachment',
        'post_mime_type' => 'audio',
        'numberposts' => -1
    );
 $audiofiles = get_posts($args);

 foreach ($audiofiles as $file)
 {
      $url = wp_get_attachment_url($file->ID);
      echo $url; // url
      echo file->post_title; //title
      echo file->post_content; // description
 }

Leave a Comment