Changeset 55169 for trunk/src/wp-includes/post.php
- Timestamp:
- 01/31/2023 04:54:22 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post.php
r55080 r55169 5661 5661 * @since 2.1.0 5662 5662 * 5663 * @global wpdb $wpdb WordPress database abstraction object.5664 *5665 5663 * @param string $page_path Page path. 5666 5664 * @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which … … 5671 5669 */ 5672 5670 function get_page_by_path( $page_path, $output = OBJECT, $post_type = 'page' ) { 5673 global $wpdb; 5674 5675 $last_changed = wp_cache_get_last_changed( 'posts' ); 5676 5677 $hash = md5( $page_path . serialize( $post_type ) ); 5678 $cache_key = "get_page_by_path:$hash:$last_changed"; 5679 $cached = wp_cache_get( $cache_key, 'posts' ); 5680 if ( false !== $cached ) { 5681 // Special case: '0' is a bad `$page_path`. 5682 if ( '0' === $cached || 0 === $cached ) { 5683 return; 5684 } else { 5685 return get_post( $cached, $output ); 5686 } 5687 } 5688 5689 $page_path = rawurlencode( urldecode( $page_path ) ); 5690 $page_path = str_replace( '%2F', '/', $page_path ); 5691 $page_path = str_replace( '%20', ' ', $page_path ); 5692 $parts = explode( '/', trim( $page_path, '/' ) ); 5693 $parts = array_map( 'sanitize_title_for_query', $parts ); 5694 $escaped_parts = esc_sql( $parts ); 5695 5696 $in_string = "'" . implode( "','", $escaped_parts ) . "'"; 5671 $page_path = rawurlencode( urldecode( $page_path ) ); 5672 $page_path = str_replace( '%2F', '/', $page_path ); 5673 $page_path = str_replace( '%20', ' ', $page_path ); 5674 $parts = explode( '/', trim( $page_path, '/' ) ); 5675 $parts = array_map( 'sanitize_title_for_query', $parts ); 5697 5676 5698 5677 if ( is_array( $post_type ) ) { … … 5702 5681 } 5703 5682 5704 $post_types = esc_sql( $post_types ); 5705 $post_type_in_string = "'" . implode( "','", $post_types ) . "'"; 5706 $sql = " 5707 SELECT ID, post_name, post_parent, post_type 5708 FROM $wpdb->posts 5709 WHERE post_name IN ($in_string) 5710 AND post_type IN ($post_type_in_string) 5711 "; 5712 5713 $pages = $wpdb->get_results( $sql, OBJECT_K ); 5683 $args = array( 5684 'post_name__in' => $parts, 5685 'post_type' => $post_types, 5686 'post_status' => 'all', 5687 'posts_per_page' => -1, 5688 'update_post_term_cache' => false, 5689 'update_post_meta_cache' => false, 5690 'no_found_rows' => true, 5691 'orderby' => 'none', 5692 ); 5693 5694 $query = new WP_Query( $args ); 5695 $posts = $query->get_posts(); 5696 $pages = array(); 5697 5698 foreach ( $posts as $post ) { 5699 $pages[ $post->ID ] = $post; 5700 } 5714 5701 5715 5702 $revparts = array_reverse( $parts ); 5716 5703 5717 5704 $foundid = 0; 5718 foreach ( (array)$pages as $page ) {5705 foreach ( $pages as $page ) { 5719 5706 if ( $page->post_name == $revparts[0] ) { 5720 5707 $count = 0; … … 5742 5729 } 5743 5730 } 5744 5745 // We cache misses as well as hits.5746 wp_cache_set( $cache_key, $foundid, 'posts' );5747 5731 5748 5732 if ( $foundid ) {
Note: See TracChangeset
for help on using the changeset viewer.