Skip to content

Instantly share code, notes, and snippets.

@damiencarbery
Last active July 17, 2020 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damiencarbery/61f74362b121dace741c75726d59bc1b to your computer and use it in GitHub Desktop.
Save damiencarbery/61f74362b121dace741c75726d59bc1b to your computer and use it in GitHub Desktop.
List all media uploaded to a WordPress site
<?php $time_start = microtime(true); ?>
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8" />
<title>List uploaded media</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<h1>List uploaded media</h1>
<pre>
<?php
define('WP_USE_THEMES', false);
require( dirname( __FILE__ ) . '/wp-blog-header.php' );
// Get list of product IDs.
$args = array('post_type'=>'attachment', 'posts_per_page' => -1, 'post_status' => 'inherit', 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false);
$the_query = new WP_Query($args);
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo wp_get_attachment_url(), "\n";
}
}
wp_reset_postdata();
echo '</pre>';
// Display some stats.
echo '<p>Memory usage: ', intval(memory_get_usage() / (1024 * 1024)), "MB\n";
echo '<br />Peak memory usage: ', intval(memory_get_peak_usage() / (1024 * 1024)), "MB</p>\n";
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "<p>Process Time: {$time} seconds.</p>";
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment