sort_by_name() function
-
There’s a sort_by_name(user_ids) that work specifically in displaying “My Friends” alphabetically.
Looking for a similar function for the members widget on the home page.
Wrote a function yesterday, but is not working. Here’s my function below.
function get_alpha_users($limit = null, $page = 1 ) {
global $wpdb, $bp;
if ( !function_exists(‘xprofile_install’) )
return false;
if ( $limit && $page )
$pag_sql = $wpdb->prepare( ” LIMIT %d, %d”, intval( ( $page – 1 ) * $limit), intval( $limit ) );
$total_users = count( $wpdb->get_results( $wpdb->prepare( “SELECT DISTINCT u.ID user_id FROM {$wpdb->base_prefix}users u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id LEFT JOIN {$bp->profile->table_name_fields} pf ON pd.field_id = pf.id WHERE u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 ORDER BY pd.value ASC”, BP_XPROFILE_FULLNAME_FIELD_NAME ) ) );
$paged_users = $wpdb->get_results( $wpdb->prepare( “SELECT DISTINCT u.ID as user_id FROM {$wpdb->base_prefix}users u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id LEFT JOIN {$bp->profile->table_name_fields} pf ON pd.field_id = pf.id WHERE u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 ORDER BY pd.value ASC{$pag_sql}”, BP_XPROFILE_FULLNAME_FIELD_NAME ) );
return array( ‘users’ => $paged_users, ‘total’ => $total_users );
}
You must be logged in to reply to this topic.