Make WordPress Core


Ignore:
Timestamp:
04/12/2005 09:12:28 PM (20 years ago)
Author:
ryan
Message:

Better page and subpage support for url_to_postid(). http://mosquito.wordpress.org/view.php?id=1214 Props: MC_incubus

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/functions.php

    r2526 r2527  
    186186        return 0;
    187187       
    188     // First, check to see if there is a 'p=N' to match against:
    189     preg_match('#[?&]p=(\d+)#', $uri, $values);
    190     $p = intval($values[1]);
     188    // First, check to see if there is a 'p=N' or 'page_id=N' to match against:
     189    preg_match('#[?&](p|page_id)=(\d+)#', $uri, $values);
     190    $p = intval($values[2]);
    191191    if ($p) return $p;
    192192   
     
    236236    // If using %post_id%, we're done:
    237237    if (intval($post_id)) return intval($post_id);
    238 
     238   
    239239    // Otherwise, build a WHERE clause, making the values safe along the way:
    240240    if ($year) $where .= " AND YEAR(post_date) = '" . intval($year) . "'";
     
    251251    }
    252252
     253    // if all we got was a postname, it's probably a page, so we'll want to check for a possible subpage
     254    if ($postname && !$year && !$monthnum && !$day && !$hour && !$minute && !$second) {
     255    $postname = rtrim(strstr($uri, $postname), '/');
     256    $uri_array = explode('/', $postname);
     257    $postname = $uri_array[count($uri_array) - 1];
     258    $where = " AND post_name = '" . $wpdb->escape($postname) . "' ";
     259    }
     260   
    253261    // Run the query to get the post ID:
    254262    $id = intval($wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE 1 = 1 " . $where));
Note: See TracChangeset for help on using the changeset viewer.