WordPress.org

Make WordPress Core

Changeset 28803


Ignore:
Timestamp:
06/23/2014 01:14:39 PM (5 years ago)
Author:
SergeyBiryukov
Message:

Prevent multiple hierarchical posts with the same slug from being displayed in single post template.

fixes #28611.

Location:
trunk
Files:
2 edited

Legend:

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

    r28783 r28803  
    23732373                    continue;
    23742374
    2375                 if ( ! $ptype_obj->hierarchical || strpos($q[ $ptype_obj->query_var ], '/') === false ) {
    2376                     // Non-hierarchical post_types & parent-level-hierarchical post_types can directly use 'name'
     2375                if ( ! $ptype_obj->hierarchical ) {
     2376                    // Non-hierarchical post types can directly use 'name'.
    23772377                    $q['name'] = $q[ $ptype_obj->query_var ];
    23782378                } else {
    2379                     // Hierarchical post_types will operate through the
     2379                    // Hierarchical post types will operate through 'pagename'.
    23802380                    $q['pagename'] = $q[ $ptype_obj->query_var ];
    23812381                    $q['name'] = '';
  • trunk/tests/phpunit/tests/query/results.php

    r28800 r28803  
    637637        $this->assertEqualSets( array( $two, $three ), $result11 );
    638638    }
     639
     640    /**
     641     * @ticket 28611
     642     */
     643    function test_duplicate_slug_in_hierarchical_post_type() {
     644        register_post_type( 'handbook', array( 'hierarchical' => true ) );
     645
     646        $post_1 = $this->factory->post->create( array( 'post_title' => 'Getting Started', 'post_type' => 'handbook' ) );
     647        $post_2 = $this->factory->post->create( array( 'post_title' => 'Contributing to the WordPress Codex', 'post_type' => 'handbook' ) );
     648        $post_3 = $this->factory->post->create( array( 'post_title' => 'Getting Started', 'post_parent' => $post_2, 'post_type' => 'handbook' ) );
     649
     650        $result = $this->q->query( array( 'handbook' => 'getting-started', 'post_type' => 'handbook' ) );
     651        $this->assertEquals( 1, $this->q->post_count );
     652    }
     653
    639654}
Note: See TracChangeset for help on using the changeset viewer.