tag__not_in and category__not_in query fixes. see #7599

git-svn-id: http://svn.automattic.com/wordpress/trunk@9031 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-09-29 21:24:24 +00:00
parent d6850f5d25
commit 3dc5beb9ce
1 changed files with 13 additions and 6 deletions

View File

@ -1803,11 +1803,11 @@ class WP_Query {
if ( !empty($q['category__not_in']) ) {
if ( $wpdb->has_cap( 'subqueries' ) ) {
$cat_string = "'" . implode("', '", $q['category__not_in']) . "'";
$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) )";
$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) )";
} else {
$ids = get_objects_in_term($q['category__not_in'], 'category');
if ( is_wp_error( $ids ) )
return $ids;
$ids = array();
if ( is_array($ids) && count($ids > 0) ) {
$out_posts = "'" . implode("', '", $ids) . "'";
$whichcat .= " AND $wpdb->posts.ID NOT IN ($out_posts)";
@ -1894,12 +1894,19 @@ class WP_Query {
}
if ( !empty($q['tag__not_in']) ) {
if ( $wpdb->has_cap( 'subqueries' ) ) {
$tag_string = "'" . implode("', '", $q['tag__not_in']) . "'";
$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) )";
} else {
$ids = get_objects_in_term($q['tag__not_in'], 'post_tag');
if ( is_wp_error( $ids ) )
$ids = array();
if ( is_array($ids) && count($ids > 0) ) {
$out_posts = "'" . implode("', '", $ids) . "'";
$whichcat .= " AND $wpdb->posts.ID NOT IN ($out_posts)";
}
}
}
// Tag and slug intersections.
$intersections = array('category__and' => 'category', 'tag__and' => 'post_tag', 'tag_slug__and' => 'post_tag');