From 5b132e4c24180e6058ead2857723267fdf539153 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Fri, 14 Sep 2012 17:19:25 +0000 Subject: [PATCH] In get_page_by_path(), attempt to return an item that has the same post type before returning an attachment with the same name. props SergeyBiryukov. tests in [UT1021]. fixes #15665. git-svn-id: https://develop.svn.wordpress.org/trunk@21845 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/post.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index 3aeec58ecb..34a5039e48 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -3306,7 +3306,7 @@ function get_page_by_path($page_path, $output = OBJECT, $post_type = 'page') { $in_string = "'". implode( "','", $parts ) . "'"; $post_type_sql = $post_type; $wpdb->escape_by_ref( $post_type_sql ); - $pages = $wpdb->get_results( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_name IN ($in_string) AND (post_type = '$post_type_sql' OR post_type = 'attachment')", OBJECT_K ); + $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 ); $revparts = array_reverse( $parts ); @@ -3325,7 +3325,8 @@ function get_page_by_path($page_path, $output = OBJECT, $post_type = 'page') { if ( $p->post_parent == 0 && $count+1 == count( $revparts ) && $p->post_name == $revparts[ $count ] ) { $foundid = $page->ID; - break; + if ( $page->post_type == $post_type ) + break; } } }