Created
February 18, 2017 04:14
-
-
Save hearvox/d64f929b7f12e1fe75f53953639df8fd to your computer and use it in GitHub Desktop.
List all images in all sizes in WordPress Media Library.
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 | |
$query_images_args = array( | |
'post_type' => 'attachment', | |
'post_status' => 'inherit', | |
'posts_per_page' => -1, | |
); | |
$query_images = new WP_Query( $query_images_args ); | |
$image_sizes = get_intermediate_image_sizes(); | |
$image_sizes[] = 'full'; | |
$images = array(); | |
foreach ( $query_images->posts as $image ) { | |
$image_meta = wp_get_attachment_metadata( $image->ID ); | |
// Array of all attachments URLs (not just images). | |
// $images[] = wp_get_attachment_url( $image->ID ); | |
// Array of of all images in all sizes. | |
foreach ( $image_sizes as $size ) { | |
if ( $image_meta['sizes'][$size] ) { | |
$images[] = $image_meta['sizes'][$size]['file']; | |
} | |
} | |
} | |
echo '<pre>'; | |
print_r( $images ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment