Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
use subquery
  • Loading branch information
Andrew Bauer committed Jan 7, 2016
1 parent 65b2e55 commit fe6cabe
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions classes.groups.php
Expand Up @@ -294,8 +294,7 @@ public function has_user($groups, $user_id) {
/**
* Get allowed post count, optionally filtered by user ID, group or post_type
*
* @todo implement cacheing with md5 of args
* @todo re-examine and optimize this query
* @todo implement caching with md5 of args
* @todo possibly move to BU_Group_Permissions
*
* @param $args array optional args
Expand Down Expand Up @@ -385,7 +384,7 @@ public function get_allowed_post_count( $args = array() ) {

}

$count_query = sprintf( "SELECT DISTINCT( ID ) FROM %s AS p LEFT JOIN %s AS m ON p.ID = m.post_ID WHERE ( m.meta_key = '%s' AND m.meta_value IN (%s) %s ) %s",
$count_query = sprintf( "SELECT ID FROM %s WHERE ( ID IN ( SELECT post_ID from %s WHERE meta_key = '%s' AND meta_value IN (%s) ) %s) %s",
$wpdb->posts,
$wpdb->postmeta,
BU_Group_Permissions::META_KEY,
Expand Down

0 comments on commit fe6cabe

Please sign in to comment.