Make WordPress Core

Ticket #15915: 15915.diff

File 15915.diff, 2.1 KB (added by greuben, 14 years ago)
  • wp-includes/rewrite.php

     
    766766        function page_uri_index() {
    767767                global $wpdb;
    768768
     769                $pages = $wpdb->get_results("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'page'", OBJECT_K);
     770                $ids = implode( ',', array_keys( $pages ) );
     771                $attachments = $wpdb->get_results("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type= 'attachment' AND post_parent IN({$ids})");
    769772                //get pages in order of hierarchy, i.e. children after parents
    770                 $posts = get_page_hierarchy($wpdb->get_results("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'page'"));
     773                $posts = get_page_hierarchy( $pages );
    771774
    772775                // If we have no pages get out quick
    773776                if ( !$posts )
     
    780783                $page_attachment_uris = array();
    781784
    782785                foreach ( $posts as $id => $post ) {
     786                        $curr_page = $pages[$id];
    783787                        // URL => page name
    784                         $uri = get_page_uri($id);
    785                         $attachments = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = %d", $id ));
    786                         if ( !empty($attachments) ) {
    787                                 foreach ( $attachments as $attachment ) {
    788                                         $attach_uri = get_page_uri($attachment->ID);
    789                                         $page_attachment_uris[$attach_uri] = $attachment->ID;
     788                        $uri = $curr_page->post_name;
     789                       
     790                        if( $curr_page->post_parent != $curr_page->ID ) {
     791                                while( $curr_page->post_parent != 0 ) {
     792                                        $curr_page = $pages[$curr_page->post_parent];
     793                                        $uri = $curr_page->post_name. "/" . $uri;
    790794                                }
    791795                        }
    792 
     796                       
    793797                        $page_uris[$uri] = $id;
    794798                }
     799               
     800                if( !empty( $attachments ) ){
     801                        foreach ( $attachments as $attachment ) {                                                               
     802                                $parent = $attachment;
     803                                $attach_uri = $attachment->post_name;
     804                                while( $parent->post_parent != 0 ){                                     
     805                                        $parent = $pages[$parent->post_parent];
     806                                        $attach_uri = $parent->post_name. "/" . $attach_uri;
     807                                }
     808                                $page_attachment_uris[$attach_uri] = $attachment->ID;
     809                        }
     810                }
    795811
    796812                return array( $page_uris, $page_attachment_uris );
    797813        }