Opened 12 years ago
Closed 12 years ago
#5904 closed defect (bug) (fixed)
No join to user meta table if key doesn't exist yet.
| Reported by: | timfield | Owned by: | imath |
|---|---|---|---|
| Priority: | normal | Milestone: | 2.2 |
| Component: | Core | Version: | 2.1 |
| Severity: | normal | 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
@
12 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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Well i guess we could force the query to fail..