Opened 10 years ago
Closed 10 years ago
#5904 closed defect (bug) (fixed)
No join to user meta table if key doesn't exist yet.
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 2.2 | Priority: | normal |
Severity: | normal | Version: | 2.1 |
Component: | Core | Keywords: | has-patch commit |
Cc: |
Description
I want to filter all members by a meta key.
add_filter('bp_before_has_members_parse_args',function($args){
if(!isset($args['scope']) || $args['scope']=='all')
{
$args['meta_key']='primary_blog';
$args['meta_value']=get_current_blog_id();
}
return $args;
});
This works, but only if at least one member has that meta key. I would expect this to always cause a join to the user meta. If no users have this meta key then none should show up.
The problem is here "public/wp-content/plugins/buddypress/bp-core/bp-core-classes.php"
// 'meta_key', 'meta_value' allow usermeta search
// To avoid global joins, do a separate query
if ( false !== $meta_key ) {
$meta_sql = $wpdb->prepare( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = %s", $meta_key );
if ( false !== $meta_value ) {
$meta_sql .= $wpdb->prepare( " AND meta_value = %s", $meta_value );
}
$found_user_ids = $wpdb->get_col( $meta_sql );
if ( ! empty( $found_user_ids ) ) {
$sql['where'][] = "u.{$this->uid_name} IN (" . implode( ',', wp_parse_id_list( $found_user_ids ) ) . ")";
}
}
Attachments (2)
Change History (7)
#2
@
10 years ago
- Keywords needs-unit-tests added; dev-feedback removed
5904.patch seems like a reasonable solution. Needs unit test, please.
Note: See
TracTickets for help on using
tickets.
Well i guess we could force the query to fail..