1

How can I export the list of all media files' url, So I can use it in some other documents?

1 Answer 1

3

You can get what you want via:

function get_the_file_urls( ) {
    $query_media_urls = array(
            'post_type'      => 'attachment',
            'post_status'    => 'inherit',
            'posts_per_page' => - 1,
    );

    $query_urls = new WP_Query( $query_media_urls );       

    foreach ( $query_urls->posts as $url ) {            
        echo '<ul>' . '<li>' . wp_get_attachment_url( $url->ID ) . '</li>' . '</ul>';
    }
}

This could either go to functions.php and then call it in a theme file via get_the_file_urls(); or you could alternatively use a plugin that allows PHP code in the post/page content as a one-off to get your list and then do whatever you want with it..

EDIT: As per the suggestion of @Bram Vanroy, which was valid and more accurately described the original question by @M0HiT to a) give credit to @pbd who originally gave this very nice example, b) save some time and c) encourage self-learning, you may have a look here and combine my answer to that by @pbd.

1
  • Might be better to immediately export as txt, since TS wants to use it in other documents as well. This saves him or her the time to copy to a document. Apr 6, 2016 at 16:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.