Changeset 9031

Show
Ignore:
Timestamp:
09/29/08 21:24:24 (3 months ago)
Author:
ryan
Message:

tagnot_in and categorynot_in query fixes. see #7599

Files:

Legend:

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

    r8968 r9031  
    18041804            if ( $wpdb->has_cap( 'subqueries' ) ) { 
    18051805                $cat_string = "'" . implode("', '", $q['category__not_in']) . "'"; 
    1806                 $whichcat .= " AND $wpdb->posts.ID NOT IN (SELECT $wpdb->term_relationships.object_id FROM $wpdb->term_relationships WHERE $wpdb->term_relationships.term_taxonomy_id IN ($cat_string) )"; 
     1806                $whichcat .= " AND $wpdb->posts.ID NOT IN ( SELECT tr.object_id FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy = 'category' AND tt.term_id IN ($cat_string) )"; 
    18071807            } else { 
    18081808                $ids = get_objects_in_term($q['category__not_in'], 'category'); 
    18091809                if ( is_wp_error( $ids ) ) 
    1810                     return $ids
     1810                    $ids = array()
    18111811                if ( is_array($ids) && count($ids > 0) ) { 
    18121812                    $out_posts = "'" . implode("', '", $ids) . "'"; 
     
    18951895 
    18961896        if ( !empty($q['tag__not_in']) ) { 
    1897             $ids = get_objects_in_term($q['tag__not_in'], 'post_tag'); 
    1898             if ( is_array($ids) && count($ids > 0) ) { 
    1899                 $out_posts = "'" . implode("', '", $ids) . "'"; 
    1900                 $whichcat .= " AND $wpdb->posts.ID NOT IN ($out_posts)"; 
     1897            if ( $wpdb->has_cap( 'subqueries' ) ) { 
     1898                $tag_string = "'" . implode("', '", $q['tag__not_in']) . "'"; 
     1899                $whichcat .= " AND $wpdb->posts.ID NOT IN ( SELECT tr.object_id FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy = 'post_tag' AND tt.term_id IN ($tag_string) )"; 
     1900            } else { 
     1901                $ids = get_objects_in_term($q['tag__not_in'], 'post_tag'); 
     1902                if ( is_wp_error( $ids ) ) 
     1903                    $ids = array(); 
     1904                if ( is_array($ids) && count($ids > 0) ) { 
     1905                    $out_posts = "'" . implode("', '", $ids) . "'"; 
     1906                    $whichcat .= " AND $wpdb->posts.ID NOT IN ($out_posts)"; 
     1907                } 
    19011908            } 
    19021909        }