Make WordPress Core

Ticket #1214: functions.php.diff

File functions.php.diff, 1.5 KB (added by MC_incubus, 21 years ago)
  • functions.php

     
    177177        if ($uri == $siteurl)
    178178                return 0;
    179179               
    180         // First, check to see if there is a 'p=N' to match against:
    181         preg_match('#[?&]p=(\d+)#', $uri, $values);
    182         $p = intval($values[1]);
     180        // First, check to see if there is a 'p=N' or 'page_id=N' to match against:
     181        preg_match('#[?&](p|page_id)=(\d+)#', $uri, $values);
     182        $p = intval($values[2]);
    183183        if ($p) return $p;
    184184       
    185185        // Match $uri against our permalink structure
     
    227227       
    228228        // If using %post_id%, we're done:
    229229        if (intval($post_id)) return intval($post_id);
    230 
     230       
    231231        // Otherwise, build a WHERE clause, making the values safe along the way:
    232232        if ($year) $where .= " AND YEAR(post_date) = '" . intval($year) . "'";
    233233        if ($monthnum) $where .= " AND MONTH(post_date) = '" . intval($monthnum) . "'";
     
    242242                return false;
    243243        }
    244244
     245        // if all we got was a postname, it's probably a page, so we'll want to check for a possible subpage
     246        if ($postname && !$year && !$monthnum && !$day && !$hour && !$minute && !$second) {
     247        $postname = rtrim(strstr($uri, $postname), '/');
     248        $uri_array = explode('/', $postname);
     249        $postname = $uri_array[count($uri_array) - 1];
     250        $where = " AND post_name = '" . $wpdb->escape($postname) . "' ";
     251        }
     252       
    245253        // Run the query to get the post ID:
    246254        $id = intval($wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE 1 = 1 " . $where));
    247255