Skip to:
Content
Pages
Categories
Search
Top
Bottom

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 );

    }

Viewing 5 replies - 1 through 5 (of 5 total)
  • 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

    Avatar of Andy Peatling
    Andy Peatling
    Keymaster

    @apeatling

    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.

    Avatar of Andy Peatling
    Andy Peatling
    Keymaster

    @apeatling

    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.

    Avatar of 21green
    21green
    Participant

    @21green

    @ 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!

Viewing 5 replies - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.