WordPress.org

Make WordPress Core

Changeset 3508


Ignore:
Timestamp:
02/09/06 08:26:30 (8 years ago)
Author:
matt
Message:

Exclude cats like we said we would, davidhouse. Fixes #2215 and fixes #2187

File:
1 edited

Legend:

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

    r3505 r3508  
    253253    $sql_exclude_cats = ''; 
    254254    if ( !empty($excluded_categories) ) { 
    255         $blah = explode('and', $excluded_categories); 
     255        $blah = explode(' and ', $excluded_categories); 
    256256        foreach ( $blah as $category ) { 
    257257            $category = intval($category); 
    258             $sql_exclude_cats .= " AND post_category != $category"; 
    259         } 
    260     } 
    261  
    262     return @$wpdb->get_row("SELECT ID, post_title FROM $wpdb->posts $join WHERE post_date < '$current_post_date' AND post_status = 'publish' $sqlcat $sql_exclude_cats ORDER BY post_date DESC LIMIT 1"); 
     258            $sql_cat_ids = " OR pc.category_ID = '$category'"; 
     259        } 
     260        $posts_in_ex_cats = $wpdb->get_col("SELECT p.ID FROM $wpdb->posts p LEFT JOIN $wpdb->post2cat pc ON pc.post_id=p.ID WHERE 1 = 0 $sql_cat_ids GROUP BY p.ID"); 
     261        $posts_in_ex_cats_sql = 'AND ID NOT IN (' . implode($posts_in_ex_cats, ',') . ')'; 
     262    } 
     263 
     264    return @$wpdb->get_row("SELECT ID, post_title FROM $wpdb->posts $join WHERE post_date < '$current_post_date' AND post_status = 'publish' $posts_in_ex_cats_sql ORDER BY post_date DESC LIMIT 1"); 
    263265} 
    264266 
     
    284286    $sql_exclude_cats = ''; 
    285287    if ( !empty($excluded_categories) ) { 
    286         $blah = explode('and', $excluded_categories); 
     288        $blah = explode(' and ', $excluded_categories); 
    287289        foreach ( $blah as $category ) { 
    288290            $category = intval($category); 
    289             $sql_exclude_cats .= " AND post_category != $category"; 
    290         } 
     291            $sql_cat_ids = " OR pc.category_ID = '$category'"; 
     292        } 
     293        $posts_in_ex_cats = $wpdb->get_col("SELECT p.ID from $wpdb->posts p LEFT JOIN $wpdb->post2cat pc ON pc.post_id = p.ID WHERE 1 = 0 $sql_cat_ids GROUP BY p.ID"); 
     294        $posts_in_ex_cats_sql = 'AND ID NOT IN (' . implode($posts_in_ex_cats, ',') . ')'; 
    291295    } 
    292296 
    293297    $now = current_time('mysql'); 
    294298     
    295     return @$wpdb->get_row("SELECT ID,post_title FROM $wpdb->posts $join WHERE post_date > '$current_post_date' AND post_date < '$now' AND post_status = 'publish' $sqlcat $sql_exclude_cats AND ID != $post->ID ORDER BY post_date ASC LIMIT 1"); 
     299    return @$wpdb->get_row("SELECT ID,post_title FROM $wpdb->posts $join WHERE post_date > '$current_post_date' AND post_date < '$now' AND post_status = 'publish' $posts_in_ex_cats_sql AND ID != $post->ID ORDER BY post_date ASC LIMIT 1"); 
    296300} 
    297301 
Note: See TracChangeset for help on using the changeset viewer.