Ticket #56689: 56689.diff
File 56689.diff, 2.4 KB (added by , 2 years ago) |
---|
-
src/wp-includes/post.php
5674 5674 * Retrieves a page given its path. 5675 5675 * 5676 5676 * @since 2.1.0 5677 *5678 * @global wpdb $wpdb WordPress database abstraction object.5679 *5680 5677 * @param string $page_path Page path. 5681 5678 * @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which 5682 5679 * correspond to a WP_Post object, an associative array, or a numeric array, … … 5685 5682 * @return WP_Post|array|null WP_Post (or array) on success, or null on failure. 5686 5683 */ 5687 5684 function get_page_by_path( $page_path, $output = OBJECT, $post_type = 'page' ) { 5688 global $wpdb;5689 5690 5685 $last_changed = wp_cache_get_last_changed( 'posts' ); 5691 5686 5692 5687 $hash = md5( $page_path . serialize( $post_type ) ); … … 5706 5701 $page_path = str_replace( '%20', ' ', $page_path ); 5707 5702 $parts = explode( '/', trim( $page_path, '/' ) ); 5708 5703 $parts = array_map( 'sanitize_title_for_query', $parts ); 5709 $escaped_parts = esc_sql( $parts );5710 5704 5711 $in_string = "'" . implode( "','", $escaped_parts ) . "'";5712 5713 5705 if ( is_array( $post_type ) ) { 5714 5706 $post_types = $post_type; 5715 5707 } else { … … 5716 5708 $post_types = array( $post_type, 'attachment' ); 5717 5709 } 5718 5710 5719 $post_types = esc_sql( $post_types ); 5720 $post_type_in_string = "'" . implode( "','", $post_types ) . "'"; 5721 $sql = " 5722 SELECT ID, post_name, post_parent, post_type 5723 FROM $wpdb->posts 5724 WHERE post_name IN ($in_string) 5725 AND post_type IN ($post_type_in_string) 5726 "; 5711 $args = array( 5712 'post_name__in' => $parts, 5713 'post_type' => $post_types, 5714 'post_status' => 'all', 5715 'posts_per_page' => -1, 5716 'update_post_term_cache' => false, 5717 'update_post_meta_cache' => false, 5718 'no_found_rows' => true, 5719 'orderby' => 'none', 5720 ); 5727 5721 5728 $pages = $wpdb->get_results( $sql, OBJECT_K ); 5722 $query = new WP_Query( $args ); 5723 $posts = $query->get_posts(); 5724 $pages = array(); 5729 5725 5726 foreach ( $posts as $post ) { 5727 $pages[ $post->ID ] = $post; 5728 } 5729 5730 5730 $revparts = array_reverse( $parts ); 5731 5731 5732 5732 $foundid = 0; 5733 foreach ( (array)$pages as $page ) {5733 foreach ( $pages as $page ) { 5734 5734 if ( $page->post_name == $revparts[0] ) { 5735 5735 $count = 0; 5736 5736 $p = $page;