Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.