Make WordPress Core

Changeset 6019


Ignore:
Timestamp:
09/03/2007 04:46:31 PM (18 years ago)
Author:
westi
Message:

Change queries in get_{next|previous}_post so that plugins can INNER JOIN on other tables with an ID column. Fixes #4822 props Cimmo.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/link-template.php

    r5995 r6019  
    366366    $join = '';
    367367    if ( $in_same_cat ) {
    368         $join = " INNER JOIN $wpdb->term_relationships AS tr ON $wpdb->posts.ID = tr.object_id ";
     368        $join = " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id ";
    369369        $cat_array = wp_get_object_terms($post->ID, 'category', 'fields=tt_ids');
    370370        $join .= ' AND (tr.term_taxonomy_id = ' . intval($cat_array[0]);
     
    379379        $blah = explode(' and ', $excluded_categories);
    380380        $posts_in_ex_cats = get_objects_in_term($blah, 'category');
    381         $posts_in_ex_cats_sql = 'AND ID NOT IN (' . implode($posts_in_ex_cats, ',') . ')';
     381        $posts_in_ex_cats_sql = 'AND p.ID NOT IN (' . implode($posts_in_ex_cats, ',') . ')';
    382382    }
    383383
    384384    $join  = apply_filters( 'get_previous_post_join', $join, $in_same_cat, $excluded_categories );
    385     $where = apply_filters( 'get_previous_post_where', "WHERE post_date < '$current_post_date' AND post_type = 'post' AND post_status = 'publish' $posts_in_ex_cats_sql", $in_same_cat, $excluded_categories );
    386     $sort  = apply_filters( 'get_previous_post_sort', 'ORDER BY post_date DESC LIMIT 1' );
    387 
    388     return @$wpdb->get_row("SELECT ID, post_title FROM $wpdb->posts $join $where $sort");
     385    $where = apply_filters( 'get_previous_post_where', "WHERE p.post_date < '$current_post_date' AND p.post_type = 'post' AND p.post_status = 'publish' $posts_in_ex_cats_sql", $in_same_cat, $excluded_categories );
     386    $sort  = apply_filters( 'get_previous_post_sort', 'ORDER BY p.post_date DESC LIMIT 1' );
     387
     388    return @$wpdb->get_row("SELECT p.ID, p.post_title FROM $wpdb->posts AS p $join $where $sort");
    389389}
    390390
     
    399399    $join = '';
    400400    if ( $in_same_cat ) {
    401         $join = " INNER JOIN $wpdb->term_relationships AS tr ON $wpdb->posts.ID = tr.object_id ";
     401        $join = " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id ";
    402402        $cat_array = wp_get_object_terms($post->ID, 'category', 'fields=tt_ids');
    403403        $join .= ' AND (tr.term_taxonomy_id = ' . intval($cat_array[0]);
     
    412412        $blah = explode(' and ', $excluded_categories);
    413413        $posts_in_ex_cats = get_objects_in_term($blah, 'category');
    414         $posts_in_ex_cats_sql = 'AND ID NOT IN (' . implode($posts_in_ex_cats, ',') . ')';
     414        $posts_in_ex_cats_sql = 'AND p.ID NOT IN (' . implode($posts_in_ex_cats, ',') . ')';
    415415    }
    416416
    417417    $join  = apply_filters( 'get_next_post_join', $join, $in_same_cat, $excluded_categories );
    418     $where = apply_filters( 'get_next_post_where', "WHERE post_date > '$current_post_date' AND post_type = 'post' AND post_status = 'publish' $posts_in_ex_cats_sql AND ID != $post->ID", $in_same_cat, $excluded_categories );
    419     $sort  = apply_filters( 'get_next_post_sort', 'ORDER BY post_date ASC LIMIT 1' );
    420 
    421     return @$wpdb->get_row("SELECT ID, post_title FROM $wpdb->posts $join $where $sort");
     418    $where = apply_filters( 'get_next_post_where', "WHERE p.post_date > '$current_post_date' AND p.post_type = 'post' AND p.post_status = 'publish' $posts_in_ex_cats_sql AND p.ID != $post->ID", $in_same_cat, $excluded_categories );
     419    $sort  = apply_filters( 'get_next_post_sort', 'ORDER BY p.post_date ASC LIMIT 1' );
     420
     421    return @$wpdb->get_row("SELECT p.ID, p.post_title FROM $wpdb->posts AS p $join $where $sort");
    422422}
    423423
Note: See TracChangeset for help on using the changeset viewer.