Changeset 27423 for trunk/src/wp-includes/post.php
- Timestamp:
- 03/05/2014 10:25:31 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post.php
r27300 r27423 3498 3498 * @param string $page_path Page path 3499 3499 * @param string $output Optional. Output type. OBJECT, ARRAY_N, or ARRAY_A. Default OBJECT. 3500 * @param string $post_type Optional. Post type. Default page.3500 * @param string|array $post_type Optional. Post type or array of post types. Default page. 3501 3501 * @return WP_Post|null WP_Post on success or null on failure 3502 3502 */ 3503 function get_page_by_path( $page_path, $output = OBJECT, $post_type = 'page') {3503 function get_page_by_path( $page_path, $output = OBJECT, $post_type = 'page' ) { 3504 3504 global $wpdb; 3505 3505 … … 3511 3511 $parts = array_map( 'sanitize_title_for_query', $parts ); 3512 3512 3513 $in_string = "'". implode( "','", $parts ) . "'"; 3514 $post_type_sql = esc_sql( $post_type ); 3515 $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 ); 3513 $in_string = "'" . implode( "','", $parts ) . "'"; 3514 3515 if ( is_array( $post_type ) ) { 3516 $post_types = $post_type; 3517 } else { 3518 $post_types = array( $post_type, 'attachment' ); 3519 } 3520 3521 $post_types = esc_sql( $post_types ); 3522 $post_type_in_string = "'" . implode( "','", $post_types ) . "'"; 3523 $sql = " 3524 SELECT ID, post_name, post_parent, post_type 3525 FROM $wpdb->posts 3526 WHERE post_name IN ($in_string) 3527 AND post_type IN ($post_type_in_string) 3528 "; 3529 3530 $pages = $wpdb->get_results( $sql, OBJECT_K ); 3516 3531 3517 3532 $revparts = array_reverse( $parts ); … … 3552 3567 * @param string $page_title Page title 3553 3568 * @param string $output Optional. Output type. OBJECT, ARRAY_N, or ARRAY_A. Default OBJECT. 3554 * @param string $post_type Optional. Post type. Default page.3569 * @param string|array $post_type Optional. Post type or array of post types. Default page. 3555 3570 * @return WP_Post|null WP_Post on success or null on failure 3556 3571 */ 3557 function get_page_by_title( $page_title, $output = OBJECT, $post_type = 'page' ) {3572 function get_page_by_title( $page_title, $output = OBJECT, $post_type = 'page' ) { 3558 3573 global $wpdb; 3559 $page = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type= %s", $page_title, $post_type ) ); 3574 3575 if ( is_array( $post_type ) ) { 3576 $post_type = esc_sql( $post_type ); 3577 $post_type_in_string = "'" . implode( "','", $post_type ) . "'"; 3578 $sql = $wpdb->prepare( " 3579 SELECT ID 3580 FROM $wpdb->posts 3581 WHERE post_title = %s 3582 AND post_type IN ($post_type_in_string) 3583 ", $page_title ); 3584 } else { 3585 $sql = $wpdb->prepare( " 3586 SELECT ID 3587 FROM $wpdb->posts 3588 WHERE post_title = %s 3589 AND post_type = %s 3590 ", $page_title, $post_type ); 3591 } 3592 3593 $page = $wpdb->get_var( $sql ); 3594 3560 3595 if ( $page ) 3561 3596 return get_post( $page, $output );
Note: See TracChangeset
for help on using the changeset viewer.