Ticket #15915: 15915.diff
File 15915.diff, 2.1 KB (added by , 14 years ago) |
---|
-
wp-includes/rewrite.php
766 766 function page_uri_index() { 767 767 global $wpdb; 768 768 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})"); 769 772 //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 ); 771 774 772 775 // If we have no pages get out quick 773 776 if ( !$posts ) … … 780 783 $page_attachment_uris = array(); 781 784 782 785 foreach ( $posts as $id => $post ) { 786 $curr_page = $pages[$id]; 783 787 // 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; 790 794 } 791 795 } 792 796 793 797 $page_uris[$uri] = $id; 794 798 } 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 } 795 811 796 812 return array( $page_uris, $page_attachment_uris ); 797 813 }