Created
January 6, 2017 12:10
-
-
Save delputnam/ece1350f6079225cc5de3acfee526059 to your computer and use it in GitHub Desktop.
Get paths of all image sizes for post attachments
This file contains hidden or 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
$args = array( | |
'posts_per_page' => 1, | |
'order' => 'ASC', | |
'post_mime_type' => 'image', | |
'post_parent' => $post_id, | |
'post_status' => null, | |
'post_type' => 'attachment', | |
); | |
$attachments = get_children( $args ); | |
foreach( $attachments as $attachment ) { | |
$image_attributes = wp_get_attachment_image_src( $attachment->ID ); | |
error_log( $image_attributes[0] ); | |
$img_url_parsed = parse_url( $image_attributes[0] ); | |
foreach( $img_url_parsed as $k => $v ) { | |
error_log( sprintf( '%s => %s', $k, $v ) ); | |
} | |
$path_parts = pathinfo( $img_url_parsed['path'] ); | |
$path = $path_parts['dirname']; | |
error_log( $attachment->ID ); | |
$meta = wp_get_attachment_metadata( $attachment->ID ); | |
foreach( $meta['sizes'] as $size ) { | |
error_log( $size['file'] ); | |
error_log( sprintf( '%s://%s/%s/%s', $img_url_parsed['scheme'], $img_url_parsed['host'], $path, $size['file'] ) ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment