Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to sort members list by xprofile value?


  • corporateslave
    Participant

    @corporateslave

    if ( bp_has_members( bp_ajax_querystring( 'members' ) ) ) :
    	do_action( 'bp_before_directory_members_list' );
    		while ( bp_members() ) : bp_the_member();
    			// the loop content goes here
    		endwhile;
    	do_action( 'bp_after_directory_members_list' );
    	bp_member_hidden_fields();
    else:
    	// and then the were none
    endif;

    Let’s say we have a simple members loop code just like the one above. And let’s say that all of our members have this xprofile field named “Lucky Number” filled accordingly.

    Can we sort out the loop output so it displays members with highest “Lucky Number” first?

    Thank you.

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

  • Venutius
    Moderator

    @venutius

    From what I can see there is no option to sort by additional fields other than those setup by default. You’d probably need to write a whole new query.


    Venutius
    Moderator

    @venutius

    Probably the easiest way to do this would be to use the existing bp_has_members query to create a new array of members results, adding the xprofile data into the new array, and then run your own loop on the array in order to sort it by the xprofile field.


    corporateslave
    Participant

    @corporateslave

    ouche… no easier way eh…

    oh well… I guess I’ll just do that for now, but I’ll keep the thread open just in case somebody have any groundbreaking idea to share about this matter.


    shanebp
    Moderator

    @shanebp

    This uses the activity loop as an example, but the approach could be modified for the members loop.

    Add custom filters to loops and enjoy them within your plugin


    corporateslave
    Participant

    @corporateslave

    @shanebp
    I apologize… but it seems like the content of that link is way over my current capacity. I have no idea what to do with whatever inside that page to help me with my task. So I’ll just bookmark that page for now.

    I would really appreciate it if someone would share a working example. Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Skip to toolbar