Make WordPress Core


Ignore:
Timestamp:
11/18/2015 07:58:01 PM (9 years ago)
Author:
wonderboymusic
Message:

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

Adds unit test.

Props SergeyBiryukov.
Fixes #24612.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/query.php

    r35285 r35679  
    18341834
    18351835        if ( '' != $qv['pagename'] ) {
    1836             $this->queried_object = get_page_by_path($qv['pagename']);
    1837             if ( !empty($this->queried_object) )
     1836            $this->queried_object = get_page_by_path( $qv['pagename'] );
     1837
     1838            if ( $this->queried_object && 'attachment' == $this->queried_object->post_type ) {
     1839                if ( preg_match( "/^[^%]*%(?:postname)%/", get_option( 'permalink_structure' ) ) ) {
     1840                    // See if we also have a post with the same slug
     1841                    $post = get_page_by_path( $qv['pagename'], OBJECT, 'post' );
     1842                    if ( $post ) {
     1843                        $this->queried_object = $post;
     1844                        $this->is_page = false;
     1845                        $this->is_single = true;
     1846                    }
     1847                }
     1848            }
     1849
     1850            if ( ! empty( $this->queried_object ) ) {
    18381851                $this->queried_object_id = (int) $this->queried_object->ID;
    1839             else
    1840                 unset($this->queried_object);
     1852            } else {
     1853                unset( $this->queried_object );
     1854            }
    18411855
    18421856            if  ( 'page' == get_option('show_on_front') && isset($this->queried_object_id) && $this->queried_object_id == get_option('page_for_posts') ) {
Note: See TracChangeset for help on using the changeset viewer.