Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wecodelaravel/909c0c8007e2cd3963e70fb4f627b4aa to your computer and use it in GitHub Desktop.
Save wecodelaravel/909c0c8007e2cd3963e70fb4f627b4aa to your computer and use it in GitHub Desktop.
List all images in all sizes in WordPress Media Library.
<?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