[buddypress-trac] [BuddyPress Trac] #5904: No join to user meta table if key doesn't exist yet.

buddypress-trac noreply at wordpress.org
Thu Sep 25 00:27:31 UTC 2014


#5904: No join to user meta table if key doesn't exist yet.
--------------------------+-----------------------------
 Reporter:  timfield      |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Core          |    Version:  2.1
 Severity:  normal        |   Keywords:  dev-feedback
--------------------------+-----------------------------
 I want to filter all members by a meta key.

 {{{#!php
 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"

 {{{#!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 ) ) . ")";
         }
 }
 }}}

--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/5904>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list