Last active
July 17, 2020 17:25
-
-
Save damiencarbery/61f74362b121dace741c75726d59bc1b to your computer and use it in GitHub Desktop.
List all media uploaded to a WordPress site
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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