Make WordPress Core


Ignore:
Timestamp:
06/19/2006 05:14:54 PM (19 years ago)
Author:
ryan
Message:

Cat exclusion from skeltoac. fixes #2825

File:
1 edited

Legend:

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

    r3869 r3886  
    709709            $join = " LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id) ";
    710710            $cat_array = preg_split('/[,\s]+/', $q['cat']);
    711             $in_cats = $out_cats = '';
     711            $in_cats = $out_cats = $out_posts = '';
    712712            foreach ( $cat_array as $cat ) {
    713713                $cat = intval($cat);
     
    723723            if ( strlen($in_cats) > 0 )
    724724                $in_cats = " AND category_id IN ($in_cats)";
    725             if ( strlen($out_cats) > 0 )
    726                 $out_cats = " AND category_id NOT IN ($out_cats)";
     725            if ( strlen($out_cats) > 0 ) {
     726                $ids = $wpdb->get_col("SELECT post_id FROM $wpdb->post2cat WHERE category_id IN ($out_cats)");
     727                if ( is_array($ids) && count($ids > 0) ) {
     728                    foreach ( $ids as $id )
     729                        $out_posts .= "$id, ";
     730                    $out_posts = substr($out_posts, 0, -2);
     731                }
     732                if ( strlen($out_posts) > 0 )
     733                    $out_cats = " AND ID NOT IN ($out_posts)";
     734            }
    727735            $whichcat = $in_cats . $out_cats;
    728736            $distinct = 'DISTINCT';
Note: See TracChangeset for help on using the changeset viewer.