Use a subquery in category__not_in query if the DB version supports it. Props pedrop. fixes #7599

git-svn-id: http://svn.automattic.com/wordpress/trunk@8738 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-08-26 19:18:58 +00:00
parent 0ee91f227e
commit e6640c911a
2 changed files with 22 additions and 6 deletions

View File

@ -1046,12 +1046,17 @@ class WP_Query {
} }
if ( !empty($q['category__not_in']) ) { if ( !empty($q['category__not_in']) ) {
$ids = get_objects_in_term($q['category__not_in'], 'category'); if ( $wpdb->supports_subqueries() ) {
if ( is_wp_error( $ids ) ) $cat_string = "'" . implode("', '", $q['category__not_in']) . "'";
return $ids; $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) )";
if ( is_array($ids) && count($ids > 0) ) { } else {
$out_posts = "'" . implode("', '", $ids) . "'"; $ids = get_objects_in_term($q['category__not_in'], 'category');
$whichcat .= " AND $wpdb->posts.ID NOT IN ($out_posts)"; if ( is_wp_error( $ids ) )
return $ids;
if ( is_array($ids) && count($ids > 0) ) {
$out_posts = "'" . implode("', '", $ids) . "'";
$whichcat .= " AND $wpdb->posts.ID NOT IN ($out_posts)";
}
} }
} }

View File

@ -923,6 +923,17 @@ class wpdb {
return ( version_compare(mysql_get_server_info($this->dbh), '4.1.0', '>=') ); return ( version_compare(mysql_get_server_info($this->dbh), '4.1.0', '>=') );
} }
/**
* Whether of not the database version supports sub-queries.
*
* @since 2.7
*
* @return bool True if sub-queries are supported, false if version does not
*/
function supports_subqueries() {
return ( version_compare(mysql_get_server_info($this->dbh), '4.1.0', '>=') );
}
/** /**
* Retrieve the name of the function that called wpdb. * Retrieve the name of the function that called wpdb.
* *