5707 | | $page_path = rawurlencode( urldecode( $page_path ) ); |
5708 | | $page_path = str_replace( '%2F', '/', $page_path ); |
5709 | | $page_path = str_replace( '%20', ' ', $page_path ); |
5710 | | $parts = explode( '/', trim( $page_path, '/' ) ); |
5711 | | $parts = array_map( 'sanitize_title_for_query', $parts ); |
5712 | | $escaped_parts = esc_sql( $parts ); |
| 5707 | $page_path = rawurlencode( urldecode( $page_path ) ); |
| 5708 | $page_path = str_replace( '%2F', '/', $page_path ); |
| 5709 | $page_path = str_replace( '%20', ' ', $page_path ); |
| 5710 | $parts = explode( '/', trim( $page_path, '/' ) ); |
| 5711 | $parts = array_map( 'sanitize_title_for_query', $parts ); |
5722 | | $post_types = esc_sql( $post_types ); |
5723 | | $post_type_in_string = "'" . implode( "','", $post_types ) . "'"; |
5724 | | $sql = " |
5725 | | SELECT ID, post_name, post_parent, post_type |
5726 | | FROM $wpdb->posts |
5727 | | WHERE post_name IN ($in_string) |
5728 | | AND post_type IN ($post_type_in_string) |
5729 | | "; |
| 5719 | /* |
| 5720 | * Perform a direct SQL query when called from 'pre_get_posts', |
| 5721 | * to avoid an infinite loop. Otherwise, use WP_Query. |
| 5722 | */ |
| 5723 | if ( doing_action( 'pre_get_posts' ) ) { |
| 5724 | $escaped_parts = esc_sql( $parts ); |
| 5725 | $in_string = "'" . implode( "','", $escaped_parts ) . "'"; |
5731 | | $pages = $wpdb->get_results( $sql, OBJECT_K ); |
| 5727 | $post_types = esc_sql( $post_types ); |
| 5728 | $post_type_in_string = "'" . implode( "','", $post_types ) . "'"; |
| 5729 | $sql = " |
| 5730 | SELECT ID, post_name, post_parent, post_type |
| 5731 | FROM $wpdb->posts |
| 5732 | WHERE post_name IN ($in_string) |
| 5733 | AND post_type IN ($post_type_in_string) |
| 5734 | "; |
| 5736 | $pages = (array) $wpdb->get_results( $sql, OBJECT_K ); |
| 5737 | } else { |
| 5738 | $args = array( |
| 5739 | 'post_name__in' => $parts, |
| 5740 | 'post_type' => $post_types, |
| 5741 | 'post_status' => 'all', |
| 5742 | 'posts_per_page' => -1, |
| 5743 | 'update_post_term_cache' => false, |
| 5744 | 'update_post_meta_cache' => false, |
| 5745 | 'no_found_rows' => true, |
| 5746 | 'orderby' => 'none', |
| 5747 | ); |
| 5748 | |
| 5749 | $query = new WP_Query( $args ); |
| 5750 | $posts = $query->get_posts(); |
| 5751 | $pages = array(); |
| 5752 | |
| 5753 | foreach ( $posts as $post ) { |
| 5754 | $pages[ $post->ID ] = $post; |
| 5755 | } |
| 5756 | } |
| 5757 | |