Make WordPress Core

Ticket #29615: 29615.patch

File 29615.patch, 1.9 KB (added by SergeyBiryukov, 10 years ago)
  • src/wp-includes/link-template.php

     
    257257
    258258        $post_type = get_post_type_object($post->post_type);
    259259
     260        if ( $post_type->hierarchical ) {
     261                $slug = get_page_uri( $id );
     262        }
     263
    260264        if ( !empty($post_link) && ( !$draft_or_pending || $sample ) ) {
    261265                if ( ! $leavename ) {
    262                         if ( $post_type->hierarchical )
    263                                 $slug = get_page_uri($id);
    264266                        $post_link = str_replace("%$post->post_type%", $slug, $post_link);
    265267                }
    266268                $post_link = home_url( user_trailingslashit($post_link) );
  • tests/phpunit/tests/query/results.php

     
    651651                $this->assertCount( 1, $result );
    652652        }
    653653
     654        /**
     655         * @ticket 29615
     656         */
     657        function test_child_post_in_hierarchical_post_type_with_default_permalinks() {
     658                global $wp_rewrite;
     659
     660                $old_permastruct = get_option( 'permalink_structure' );
     661                $wp_rewrite->set_permalink_structure( '' );
     662                $wp_rewrite->flush_rules();
     663
     664                register_post_type( 'handbook', array( 'hierarchical' => true ) );
     665
     666                $post_1 = $this->factory->post->create( array( 'post_title' => 'Contributing to the WordPress Codex', 'post_type' => 'handbook' ) );
     667                $post_2 = $this->factory->post->create( array( 'post_title' => 'Getting Started', 'post_parent' => $post_1, 'post_type' => 'handbook' ) );
     668
     669                $this->assertContains( 'contributing-to-the-wordpress-codex/getting-started', get_permalink( $post_2 ) );
     670
     671                $result = $this->q->query( array( 'handbook' => 'contributing-to-the-wordpress-codex/getting-started', 'post_type' => 'handbook' ) );
     672                $this->assertCount( 1, $result );
     673
     674                $wp_rewrite->set_permalink_structure( $old_permastruct );
     675                $wp_rewrite->flush_rules();
     676        }
     677
    654678}