Make WordPress Core


Ignore:
Timestamp:
05/24/2004 08:22:18 AM (21 years ago)
Author:
saxmatt
Message:

Giant commit, sorry mailing list people. Move all table names to new $wpdb versions. Works but the whole app needs thorough testing now.

File:
1 edited

Legend:

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

    r1353 r1355  
    77 */
    88function wp_insert_post($postarr = array()) {
    9     global $wpdb, $tableposts, $post_default_category;
     9    global $wpdb, $post_default_category;
    1010   
    1111    // export array as variables
     
    3232        $post_date_gmt = get_gmt_from_date($post_date);
    3333   
    34     $sql = "INSERT INTO $tableposts
     34    $sql = "INSERT INTO $wpdb->posts
    3535        (post_author, post_date, post_date_gmt, post_modified, post_modified_gmt, post_content, post_title, post_excerpt, post_category, post_status, post_name)
    3636        VALUES ('$post_author', '$post_date', '$post_date_gmt', '$post_date', '$post_date_gmt', '$post_content', '$post_title', '$post_excerpt', '$post_cat', '$post_status', '$post_name')";
     
    5050
    5151function wp_get_single_post($postid = 0, $mode = OBJECT) {
    52     global $wpdb, $tableposts;
    53 
    54     $sql = "SELECT * FROM $tableposts WHERE ID=$postid";
     52    global $wpdb;
     53
     54    $sql = "SELECT * FROM $wpdb->posts WHERE ID=$postid";
    5555    $result = $wpdb->get_row($sql, $mode);
    5656   
     
    6262
    6363function wp_get_recent_posts($num = 10) {
    64     global $wpdb, $tableposts;
     64    global $wpdb;
    6565
    6666    // Set the limit clause, if we got a limit
     
    6969    }
    7070
    71     $sql = "SELECT * FROM $tableposts ORDER BY post_date DESC $limit";
     71    $sql = "SELECT * FROM $wpdb->posts ORDER BY post_date DESC $limit";
    7272    $result = $wpdb->get_results($sql,ARRAY_A);
    7373
     
    7676
    7777function wp_update_post($postarr = array()) {
    78     global $wpdb, $tableposts;
     78    global $wpdb;
    7979
    8080    // First get all of the original fields
     
    9797    $post_modified_gmt = current_time('mysql', 1);
    9898
    99     $sql = "UPDATE $tableposts
     99    $sql = "UPDATE $wpdb->posts
    100100        SET post_content = '$post_content',
    101101        post_title = '$post_title',
     
    119119
    120120function wp_get_post_cats($blogid = '1', $post_ID = 0) {
    121     global $wpdb, $tablepost2cat;
     121    global $wpdb;
    122122   
    123123    $sql = "SELECT category_id
    124         FROM $tablepost2cat
     124        FROM $wpdb->post2cat
    125125        WHERE post_id = $post_ID
    126126        ORDER BY category_id";
     
    132132
    133133function wp_set_post_cats($blogid = '1', $post_ID = 0, $post_categories = array()) {
    134     global $wpdb, $tablepost2cat;
     134    global $wpdb;
    135135    // If $post_categories isn't already an array, make it one:
    136136    if (!is_array($post_categories)) {
     
    146146    $old_categories = $wpdb->get_col("
    147147        SELECT category_id
    148         FROM $tablepost2cat
     148        FROM $wpdb->post2cat
    149149        WHERE post_id = $post_ID");
    150150   
     
    169169        foreach ($delete_cats as $del) {
    170170            $wpdb->query("
    171                 DELETE FROM $tablepost2cat
     171                DELETE FROM $wpdb->post2cat
    172172                WHERE category_id = $del
    173173                    AND post_id = $post_ID
     
    186186        foreach ($add_cats as $new_cat) {
    187187            $wpdb->query("
    188                 INSERT INTO $tablepost2cat (post_id, category_id)
     188                INSERT INTO $wpdb->post2cat (post_id, category_id)
    189189                VALUES ($post_ID, $new_cat)");
    190190
     
    195195
    196196function wp_delete_post($postid = 0) {
    197     global $wpdb, $tableposts, $tablepost2cat;
    198    
    199     $sql = "DELETE FROM $tablepost2cat WHERE post_id = $postid";
     197    global $wpdb;
     198   
     199    $sql = "DELETE FROM $wpdb->post2cat WHERE post_id = $postid";
    200200    $wpdb->query($sql);
    201201       
    202     $sql = "DELETE FROM $tableposts WHERE ID = $postid";
     202    $sql = "DELETE FROM $wpdb->posts WHERE ID = $postid";
    203203   
    204204    $wpdb->query($sql);
     
    216216function post_permalink($post_ID=0, $mode = 'id') {
    217217    global $wpdb;
    218     global $tableposts;
    219218    global $querystring_start, $querystring_equal, $querystring_separator;
    220219
     
    266265// Get the name of a category from its ID
    267266function get_cat_name($cat_id) {
    268     global $wpdb,$tablecategories;
     267    global $wpdb;
    269268   
    270269    $cat_id -= 0;   // force numeric
    271     $name = $wpdb->get_var("SELECT cat_name FROM $tablecategories WHERE cat_ID=$cat_id");
     270    $name = $wpdb->get_var("SELECT cat_name FROM $wpdb->categories WHERE cat_ID=$cat_id");
    272271   
    273272    return $name;
     
    276275// Get the ID of a category from its name
    277276function get_cat_ID($cat_name='General') {
    278     global $wpdb,$tablecategories;
    279    
    280     $cid = $wpdb->get_var("SELECT cat_ID FROM $tablecategories WHERE cat_name='$cat_name'");
     277    global $wpdb;
     278   
     279    $cid = $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE cat_name='$cat_name'");
    281280
    282281    return $cid?$cid:1; // default to cat 1
Note: See TracChangeset for help on using the changeset viewer.