Ticket #24763: get_page_by_path_v4.patch
File get_page_by_path_v4.patch, 2.7 KB (added by , 11 years ago) |
---|
-
wp-includes/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, 'attachment' ); 3536 } 3537 $post_types = esc_sql( $post_types ); 3538 3539 $post_type_in_string = "'" . implode( "','", $post_types ) . "'"; 3540 3541 $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 ); 3542 3533 3543 $revparts = array_reverse( $parts ); 3534 3544 3535 3545 $foundid = 0; … … 3567 3577 * 3568 3578 * @param string $page_title Page title 3569 3579 * @param string $output Optional. Output type. OBJECT, ARRAY_N, or ARRAY_A. Default OBJECT. 3570 * @param string $post_type Optional. Post type. Default page.3580 * @param string|Array $post_type Optional. Post type or array of post types. Default page. 3571 3581 * @return WP_Post|null WP_Post on success or null on failure 3572 3582 */ 3573 3583 function get_page_by_title($page_title, $output = OBJECT, $post_type = 'page' ) { 3574 3584 global $wpdb; 3575 $page = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type= %s", $page_title, $post_type ) );3576 if ( $page )3577 return get_post( $page, $output );3578 3585 3579 return null; 3586 if ( is_array( $post_type ) ) { 3587 $post_type = esc_sql( $post_type ); 3588 $post_type_in_string = "'" . implode( "','", $post_type ) . "'"; 3589 3590 $sql = $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type IN ($post_type_in_string)", $page_title ); 3591 } 3592 else { 3593 $sql = $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type= %s", $page_title, $post_type ); 3594 } 3595 3596 $page = $wpdb->get_var( $sql ); 3597 3598 if ( ! $page ) { 3599 return null; 3600 } 3601 3602 return get_post( $page, $output ); 3580 3603 } 3581 3604 3582 3605 /**