Ticket #24763: get_page_by_path.patch
File get_page_by_path.patch, 1.5 KB (added by , 11 years ago) |
---|
-
post.php
3513 3513 * 3514 3514 * @param string $page_path Page path 3515 3515 * @param string $output Optional. Output type. OBJECT, ARRAY_N, or ARRAY_A. Default OBJECT. 3516 * @param string $post_type Optional. Post type. Default page.3516 * @param string|Array $post_type Optional. Post type or array of post types. Default page. 3517 3517 * @return WP_Post|null WP_Post on success or null on failure 3518 3518 */ 3519 3519 function get_page_by_path($page_path, $output = OBJECT, $post_type = 'page') { … … 3527 3527 $parts = array_map( 'sanitize_title_for_query', $parts ); 3528 3528 3529 3529 $in_string = "'". implode( "','", $parts ) . "'"; 3530 $post_type_sql = esc_sql( $post_type );3531 $pages = $wpdb->get_results( "SELECT ID, post_name, post_parent, post_type FROM $wpdb->posts WHERE post_name IN ($in_string) AND (post_type = '$post_type_sql' OR post_type = 'attachment')", OBJECT_K );3532 3530 3531 if ( is_array( $post_type ) ) { 3532 $post_types = $post_type; 3533 } 3534 else { 3535 $post_types = array( $post_type ); 3536 } 3537 $post_types[] = 'attachment'; 3538 $post_types = esc_sql( $post_types ); 3539 3540 $post_type_in_string = "'" . implode( "','", $post_types ) . "'"; 3541 3542 $pages = $wpdb->get_results( $sql = "SELECT ID, post_name, post_parent, post_type FROM $wpdb->posts WHERE post_name IN ($in_string) AND post_type IN ($post_type_in_string)", OBJECT_K ); 3543 3533 3544 $revparts = array_reverse( $parts ); 3534 3545 3535 3546 $foundid = 0;