| | 786 | |
| | 787 | // get_page_uri() calls get_post(), so pre-fill the cache to avoid db calls |
| | 788 | $pages = $wpdb->get_results(" |
| | 789 | SELECT pages.* |
| | 790 | FROM $wpdb->posts as pages |
| | 791 | WHERE pages.post_type = 'page' |
| | 792 | AND pages.post_status IN ('publish', 'private') |
| | 793 | "); |
| | 794 | |
| | 795 | if ( !$pages ) |
| | 796 | return array(array(), array()); |
| | 797 | |
| | 798 | update_post_cache($pages); |
| | 799 | |
| | 800 | // get pages in order of hierarchy, i.e. children after parents |
| | 801 | $pages = get_page_hierarchy($pages); |
| | 802 | |
| | 803 | // now reverse it, because we need parents after children for rewrite rules to work properly |
| | 804 | $pages = array_reverse($pages, true); |
| 787 | | //get pages in order of hierarchy, i.e. children after parents |
| 788 | | $posts = get_page_hierarchy($wpdb->get_results("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'page'")); |
| 789 | | //now reverse it, because we need parents after children for rewrite rules to work properly |
| 790 | | $posts = array_reverse($posts, true); |
| 791 | | |
| | 806 | // pre-fill the cache for page attachments, since they call get_post() as well |
| | 807 | $page_attachments = $wpdb->get_results(" |
| | 808 | SELECT attachments.* |
| | 809 | FROM $wpdb->posts as attachments |
| | 810 | JOIN $wpdb->posts as pages |
| | 811 | ON pages.ID = attachments.post_parent |
| | 812 | WHERE attachments.post_type = 'attachment' |
| | 813 | AND pages.post_type = 'page' |
| | 814 | AND pages.post_status IN ('publish', 'private') |
| | 815 | "); |
| | 816 | |
| | 817 | update_post_cache($page_attachments); |
| | 818 | |
| | 819 | // extract array of $page_id => array of $attachment_id |
| | 820 | $attachments = array(); |
| | 821 | foreach ( $page_attachments as $attachment ) |
| | 822 | $attachments[$attachment->post_parent][] = $attachment->ID; |
| | 823 | |
| 800 | | $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; |
| 806 | | } |
| | 829 | $page_uri = get_page_uri($page_id); |
| | 830 | $page_uris[$page_uri] = $page_id; |
| | 831 | |
| | 832 | foreach ( (array) $attachments[$page_id] as $attachment_id ) { |
| | 833 | $attachment_uri = get_page_uri($attachment_id); |
| | 834 | $page_attachment_uris[$attachment_uri] = $attachment_id; |