Created
December 11, 2014 13:24
-
-
Save tormjens/97baf3c3550b5b7bbea1 to your computer and use it in GitHub Desktop.
BuddyPress: Show users that do not have groups based on a get parameter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Filters the query | |
* | |
* @param string $query The query instance | |
* @param array $sql The array of the query to be run | |
* | |
* @return array | |
**/ | |
function bp_filter_member_query( $query, $sql ) { | |
$key = 'group_id'; // the key to check agains | |
$do_filter = isset($_GET[$key]) && $_GET[$key] === 'none' ? true : false; // should return true or false | |
if( $do_filter ) { | |
global $wpdb; | |
$qry = "u.ID not in ( | |
SELECT user_id FROM {$wpdb->usermeta} | |
where meta_key = 'total_group_count' | |
and meta_value != 0 | |
)"; | |
$query['where'][] = $qry; | |
} | |
return $query; | |
} | |
add_filter( 'bp_user_query_uid_clauses', 'bp_filter_member_query', 20, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment