Use a subquery in category__not_in query if the DB version supports it. Props pedrop. fixes #7599
git-svn-id: https://develop.svn.wordpress.org/trunk@8738 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
f47f0a2ddd
commit
13cf1a5c78
@ -1046,6 +1046,10 @@ class WP_Query {
|
||||
}
|
||||
|
||||
if ( !empty($q['category__not_in']) ) {
|
||||
if ( $wpdb->supports_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) )";
|
||||
} else {
|
||||
$ids = get_objects_in_term($q['category__not_in'], 'category');
|
||||
if ( is_wp_error( $ids ) )
|
||||
return $ids;
|
||||
@ -1054,6 +1058,7 @@ class WP_Query {
|
||||
$whichcat .= " AND $wpdb->posts.ID NOT IN ($out_posts)";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Category stuff for nice URLs
|
||||
if ( '' != $q['category_name'] && !$this->is_singular ) {
|
||||
|
@ -923,6 +923,17 @@ class wpdb {
|
||||
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.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user