bp_core_search_users_sql

  • apply_filters( 'bp_core_search_users_sql', "SELECT DISTINCT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.user_email FROM {$wpdb->users} u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id WHERE {$status_sql} AND

    Source Reference:

    • Component: BuddyPress :: bp-core
      File: /bp-core/bp-core-classes.php :: Trac Source Line: 477
      	function search_users( $search_terms, $limit = null, $page = 1, $populate_extras = true ) {
      		global $bp, $wpdb;
      
      		$pag_sql = $limit && $page ? $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * intval( $limit ) ), intval( $limit ) ) : '';
      
      		$search_terms = like_escape( $wpdb->escape( $search_terms ) );
      		$status_sql   = bp_core_get_status_sql( 'u.' );
      
      		$total_users_sql = apply_filters( 'bp_core_search_users_count_sql', "SELECT COUNT(DISTINCT u.ID) as id FROM {$wpdb->users} u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id WHERE {$status_sql} AND pd.value LIKE '%%$search_terms%%' ORDER BY pd.value ASC", $search_terms );
      		$paged_users_sql = apply_filters( 'bp_core_search_users_sql', "SELECT DISTINCT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.user_email FROM {$wpdb->users} u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id WHERE {$status_sql} AND pd.value LIKE '%%$search_terms%%' ORDER BY pd.value ASC{$pag_sql}", $search_terms, $pag_sql );
      
      		$total_users = $wpdb->get_var( $total_users_sql );
      		$paged_users = $wpdb->get_results( $paged_users_sql );
      
      		/***
      		 * Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list.
      		 * We can't add these to the main query above since only users who have this information will be returned (since the much of the data is in usermeta and won't support any type of directional join)
      		 */
      		foreach ( (array)$paged_users as $user )
      			$user_ids[] = $user->id;
      

Comments are closed.