Rewrite: alleviate conflicts between image attachment pages and posts when permalink structure is /%postname%/.

Adds unit test.

Props SergeyBiryukov.
Fixes #24612.

Built from https://develop.svn.wordpress.org/trunk@35679


git-svn-id: http://core.svn.wordpress.org/trunk@35643 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2015-11-18 19:59:25 +00:00
parent 13ea469061
commit af0282891d
2 changed files with 19 additions and 5 deletions

View File

@ -1833,11 +1833,25 @@ class WP_Query {
} }
if ( '' != $qv['pagename'] ) { if ( '' != $qv['pagename'] ) {
$this->queried_object = get_page_by_path($qv['pagename']); $this->queried_object = get_page_by_path( $qv['pagename'] );
if ( !empty($this->queried_object) )
if ( $this->queried_object && 'attachment' == $this->queried_object->post_type ) {
if ( preg_match( "/^[^%]*%(?:postname)%/", get_option( 'permalink_structure' ) ) ) {
// See if we also have a post with the same slug
$post = get_page_by_path( $qv['pagename'], OBJECT, 'post' );
if ( $post ) {
$this->queried_object = $post;
$this->is_page = false;
$this->is_single = true;
}
}
}
if ( ! empty( $this->queried_object ) ) {
$this->queried_object_id = (int) $this->queried_object->ID; $this->queried_object_id = (int) $this->queried_object->ID;
else } else {
unset($this->queried_object); unset( $this->queried_object );
}
if ( 'page' == get_option('show_on_front') && isset($this->queried_object_id) && $this->queried_object_id == get_option('page_for_posts') ) { if ( 'page' == get_option('show_on_front') && isset($this->queried_object_id) && $this->queried_object_id == get_option('page_for_posts') ) {
$this->is_page = false; $this->is_page = false;

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.4-beta4-35678'; $wp_version = '4.4-beta4-35679';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.