WordPress.org

Make WordPress Core

Ticket #3614: page_attachment_query.diff

File page_attachment_query.diff, 1.3 KB (added by ryan, 7 years ago)

Query page attachments from page requests

  • wp-includes/query.php

     
    841841                                $q['pagename'] = sanitize_title(basename($page_paths)); 
    842842                                $q['name'] = $q['pagename']; 
    843843                                $where .= " AND (ID = '$reqpage')"; 
     844                                $reqpage_obj = get_page($reqpage); 
     845                                if ( 'attachment' == $reqpage_obj->post_type ) { 
     846                                        $this->is_attachment = true; 
     847                                        $this->is_page = false; 
     848                                        $q['attachment_id'] = $reqpage; 
     849                                } 
    844850                        } 
    845851                } elseif ('' != $q['attachment']) { 
    846852                        $q['attachment'] = str_replace('%2F', '/', urlencode(urldecode($q['attachment']))); 
  • wp-includes/post.php

     
    976976        foreach($page_paths as $pathdir) 
    977977                $full_path .= ($pathdir!=''?'/':'') . sanitize_title($pathdir); 
    978978 
    979         $pages = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_name = %s AND post_type='page'", $leaf_path )); 
     979        $pages = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_name = %s AND (post_type = 'page' OR post_type = 'attachment')", $leaf_path )); 
    980980 
    981981        if ( empty($pages) ) 
    982982                return NULL;