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 );
}
-
My facebook inspired theme here http://bit.ly/VceH6
Any idea on how to implement a sort_by_name functionality to the members widget on the home page?
Thanks
You’re better off using the new users template tags. Check out the members directory template loop in the member theme in the latest trunk.
bp-themes/buddypress-member/directories/members/members-loop.php
You can set specific ways to order members:
bp_has_site_members( 'type=alphabetical&per_page=10' ) )
type can be: active ( default ) | random | newest | popular | online | alphabetical
This is only in the latest trunk, not RC1.
You’d have to make your own widget and use the template tags. That’s your best bet.
Thanks, I’ll give that a shot.
@ Andy: Nice new feature! Will such function also be available for the recent blog posts widget, say at least to switch between the newest entries and the mots popular ones?
We need more filter to organize the content, members and groups! WordPress.com shows how to do it!
Anyway, thanks so much for this great WPMU Plugins!
- The topic ‘sort_by_name() function’ is closed to new replies.