Make WordPress Core

Changeset 29765


Ignore:
Timestamp:
09/24/2014 09:29:15 PM (10 years ago)
Author:
SergeyBiryukov
Message:

Create correct permalinks for child posts of hierarchical post types when default permalinks are used.

props loushou.
fixes #29615 for trunk.

Location:
trunk
Files:
2 edited

Legend:

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

    r29375 r29765  
    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        }
  • trunk/tests/phpunit/tests/query/results.php

    r28809 r29765  
    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}
Note: See TracChangeset for help on using the changeset viewer.