How to get the URL of an attachment as used in the post
-
Hello,
I can’t figure out how to get the real images URLs from a post. Below is the function I use to get the URLs of the images from a specific post.
private function get_images($post_id) { $images = array(); $argsThumb = array( 'order' => 'ASC', 'post_type' => 'attachment', 'post_parent' => $post_id, 'post_mime_type' => 'image', 'post_status' => NULL ); $attachments = get_posts( $argsThumb ); if ( $attachments ) { foreach ( $attachments as $attachment ) { log_me( wp_get_attachment_url( $attachment->ID ) ); log_me( $attachment->post_title ); log_me( $attachment->post_name ); log_me( print_r( $attachment, true ) ); $images[] = wp_get_attachment_url( $attachment->ID ); } } return $images; }
This code works great, but it doesn’t give the real URL of the images in the post. E.g. in the post there is an image with URL https://localhost/blog/wp-content/uploads/2013/04/example-300×183.jpg
Unfortunately, the function above will only return https://localhost/blog/wp-content/uploads/2013/04/example.jpg
Anyone has an idea how to get *the actual images* used in a specific post?
Thank you
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘How to get the URL of an attachment as used in the post’ is closed to new replies.