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/query.php

    r13770 r13774  
    17131713            $where .= " AND DAYOFMONTH($wpdb->posts.post_date)='" . $q['day'] . "'";
    17141714
    1715         if ('' != $q['name']) {
     1715        if ( !empty($q['post_type']) && !empty($q[ $q['post_type'] ]) ) {
     1716            $q[ $q['post_type'] ] = str_replace('%2F', '/', urlencode(urldecode($q[ $q['post_type'] ])));
     1717            $post_type_object = get_post_type_object($q['post_type']);
     1718            if ( ! $post_type_object->hierarchical || strpos($q[ $q['post_type'] ], '/') === false) {
     1719                $q['name'] = $q[ $q['post_type'] ] = sanitize_title($q[ $q['post_type'] ]);
     1720                $where .= " AND $wpdb->posts.post_name = '" . $q[ $q['post_type'] ] . "'";         
     1721            } else {
     1722                // Hierarchical post type, need to look deeper to see if its an attachment or this post_type
     1723                if ( isset($this->queried_object_id) ) {
     1724                    $reqpage = $this->queried_object_id;
     1725                } else {
     1726                    $reqpage = get_page_by_path($q[ $q['post_type'] ], OBJECT, $q['post_type']);
     1727                    if ( !empty($reqpage) )
     1728                        $reqpage = $reqpage->ID;
     1729                    else
     1730                        $reqpage = 0;
     1731                }
     1732                $where .= " AND ($wpdb->posts.ID = '$reqpage')";
     1733                $reqpage_obj = get_page($reqpage);
     1734                if ( is_object($reqpage_obj) && 'attachment' == $reqpage_obj->post_type ) {
     1735                    $this->is_attachment = true;
     1736                    $q['attachment_id'] = $reqpage;
     1737                    $post_type = $q['post_type'] = 'attachment';
     1738                }
     1739            }
     1740        } elseif ( '' != $q['name'] ) {
    17161741            $q['name'] = sanitize_title($q['name']);
    17171742            $where .= " AND $wpdb->posts.post_name = '" . $q['name'] . "'";
    1718         } else if ('' != $q['pagename']) {
     1743        } elseif ( '' != $q['pagename'] ) {
    17191744            if ( isset($this->queried_object_id) )
    17201745                $reqpage = $this->queried_object_id;
     
    17281753
    17291754            $page_for_posts = get_option('page_for_posts');
    1730             if  ( ('page' != get_option('show_on_front') ) ||  empty($page_for_posts) || ( $reqpage != $page_for_posts ) ) {
     1755            if  ( ('page' != get_option('show_on_front') ) || empty($page_for_posts) || ( $reqpage != $page_for_posts ) ) {
    17311756                $q['pagename'] = str_replace('%2F', '/', urlencode(urldecode($q['pagename'])));
    17321757                $page_paths = '/' . trim($q['pagename'], '/');
Note: See TracChangeset for help on using the changeset viewer.