WordPress.org

Make WordPress Core

Ticket #15665: garyc40.15665.diff

File garyc40.15665.diff, 1.0 KB (added by garyc40, 5 years ago)

fixed get_page_by_path()

  • wp-includes/post.php

    diff --git wp-includes/post.php wp-includes/post.php
    index c4422bc..f0040a9 100644
    function get_page_by_path($page_path, $output = OBJECT, $post_type = 'page') { 
    31333133        foreach ( (array) $page_paths as $pathdir ) 
    31343134                $full_path .= ( $pathdir != '' ? '/' : '' ) . sanitize_title($pathdir); 
    31353135 
    3136         $pages = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_name = %s AND (post_type = %s OR post_type = 'attachment')", $leaf_path, $post_type )); 
     3136        $pages = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent, post_type FROM $wpdb->posts WHERE post_name = %s AND (post_type = %s OR post_type = 'attachment')", $leaf_path, $post_type )); 
    31373137 
    31383138        if ( empty($pages) ) 
    31393139                return $null; 
    31403140 
    31413141        foreach ( $pages as $page ) { 
    3142                 $path = '/' . $leaf_path; 
     3142                $path = '/' . ( $page->post_type == 'attachment' ? 'attachment/' : '' ) . $leaf_path; 
    31433143                $curpage = $page; 
    31443144                while ( $curpage->post_parent != 0 ) { 
    31453145                        $post_parent = $curpage->post_parent;