Skip to:
Content
Pages
Categories
Search
Top
Bottom

New Orderby Option for Members using a Field Created by Advanced Custom Fields


  • bascazubi
    Participant

    @bascazubi

    Hi All,

    This is my first time posting on the buddypress support forum. I need some assistance with a project I am working on. This website i am working on will be keeping track of a custom field that will work similar to a points system. I am looking to create a custom members page with the orderby filter to have an option to display the users as a leader board. I have tried adding this I manipulated from another post in the theme’s functions.php file. The issues is once I get to the loop of the new page I am unable to display the sorted information in the order created by the function below. Any help would be greatly appreciated.

    
    function du_users_by_value($field_id){
    $numberedUsers = array();
    $orderedIds = array();
    
    if ( bp_has_members(bp_ajax_querystring( 'members' ) ) ) : while ( bp_members() ) : bp_the_member();
    // Get the field value from all members
    $display_id = bp_get_member_user_id();
    $number_field = get_user_meta($display_id,$field_id,true);
    
    // Push user id and number value to an array
    $numberedUsers[$display_id] = $number_field;
    endwhile;
    endif;
    //print_r($numberedUsers);
    
    // Sort the members by the custom field value, highest to lowest 
    arsort($numberedUsers);
    //print_r($numberedUsers);
    
    // Create a new array with just the member id’s in the correct order
    foreach ($numberedUsers as $user => $value) {
    array_push($orderedIds, $user);
    }
    print_r($orderedIds);
    
    // Echo out the include argument along with comma seperated values of the members in order 
    $orderedIds=implode(",",$orderedIds);
    //echo 'include=' . $orderedIds;
    return $orderedIds;
    }
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘New Orderby Option for Members using a Field Created by Advanced Custom Fields’ is closed to new replies.
Skip to toolbar