WordPress.org

Make WordPress Core


Ignore:
Timestamp:
03/20/2010 02:23:52 AM (10 years ago)
Author:
dd32
Message:

Add hierarchical support for custom post_types in Rewrite Rules & Querying. See #12643

File:
1 edited

Legend:

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

    r13733 r13774  
    188188    $draft_or_pending = 'draft' == $post->post_status || 'pending' == $post->post_status;
    189189
     190    $post_type = get_post_type_object($post->post_type);
     191
    190192    if ( !empty($post_link) && ( ( isset($post->post_status) && !$draft_or_pending ) || $sample ) ) {
    191         $post_link = ( $leavename ) ? $post_link : str_replace("%$post->post_type%", $slug, $post_link);
     193        if ( ! $leavename ) {
     194            if ( $post_type->hierarchical )
     195                $slug = get_page_uri($id);
     196            $post_link = str_replace("%$post->post_type%", $slug, $post_link);
     197        }
    192198        $post_link = home_url( user_trailingslashit($post_link) );
    193199    } else {
    194         $post_type = get_post_type_object($post->post_type);
    195200        if ( $post_type->query_var && ( isset($post->post_status) && !$draft_or_pending ) )
    196201            $post_link = add_query_arg($post_type->query_var, $slug, '');
     
    296301    $link = false;
    297302
    298     if (! $id) {
     303    if ( ! $id)
    299304        $id = (int) $post->ID;
    300     }
    301305
    302306    $object = get_post($id);
     
    307311        else
    308312            $parentlink = get_permalink( $object->post_parent );
     313
    309314        if ( is_numeric($object->post_name) || false !== strpos(get_option('permalink_structure'), '%category%') )
    310315            $name = 'attachment/' . $object->post_name; // <permalink>/<int>/ is paged so we use the explicit attachment marker
    311316        else
    312317            $name = $object->post_name;
    313         if (strpos($parentlink, '?') === false)
     318
     319        if ( strpos($parentlink, '?') === false )
    314320            $link = user_trailingslashit( trailingslashit($parentlink) . $name );
    315321    }
    316322
    317     if (! $link ) {
     323    if ( ! $link )
    318324        $link = trailingslashit(get_bloginfo('url')) . "?attachment_id=$id";
    319     }
    320325
    321326    return apply_filters('attachment_link', $link, $id);
Note: See TracChangeset for help on using the changeset viewer.