### Eclipse Workspace Patch 1.0
#P wordpress-dev
|
|
|
|
| 794 | 794 | |
| 795 | 795 | if ( !$posts ) |
| 796 | 796 | return array( array(), array() ); |
| 797 | | |
| | 797 | |
| | 798 | // get the set of posts with an attachment to reduce the number of queries inside the loop |
| | 799 | $all_attachments = $wpdb->get_results( "SELECT post_parent FROM $wpdb->posts WHERE post_type = 'attachment'" ); |
| | 800 | |
| 798 | 801 | foreach ($posts as $id => $post) { |
| | 802 | |
| 799 | 803 | // URL => page name |
| 800 | 804 | $uri = get_page_uri($id); |
| 801 | | $attachments = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = %d", $id )); |
| 802 | | if ( $attachments ) { |
| 803 | | foreach ( $attachments as $attachment ) { |
| 804 | | $attach_uri = get_page_uri($attachment->ID); |
| 805 | | $page_attachment_uris[$attach_uri] = $attachment->ID; |
| | 805 | if (in_array( $id, $all_attachments )) { |
| | 806 | $attachments = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = %d", $id )); |
| | 807 | if ( $attachments ) { |
| | 808 | foreach ( $attachments as $attachment ) { |
| | 809 | $attach_uri = get_page_uri($attachment->ID); |
| | 810 | $page_attachment_uris[$attach_uri] = $attachment->ID; |
| | 811 | } |
| 806 | 812 | } |
| 807 | 813 | } |
| 808 | 814 | |