Skip to:
Content
Pages
Categories
Search
Top
Bottom

Custom Sort of Group Members

  • Avatar of Dimensionmedia
    David Bisset
    Participant

    @dimensionmedia

    I know the general current state of sorting group members, but wondering if i had to do this TODAY what the recommended plan of attack would be.

    Basically I would love a filter in the get_group_member_ids() function of BP_Group_Member_Query class – i want to be able to do my own sql, then pass that along (or the output). Similar to how one can do so for all the members via bp_core_get_users.

    So recommendations for the best way to handle this so that the group member loop is preserved… otherwise i might as well bypass it (in this instance) and generate my own query and output (but i hate coding pagination).

Viewing 12 replies - 1 through 12 (of 12 total)
  • Avatar of Dimensionmedia
    David Bisset
    Participant

    @dimensionmedia

    BTW, the sort in this instance is sorting with user meta. Not the best setup, I admit. But my point was that i want to be able to generate my own SQL and pass it back in somewhere along the line.

    And yes, using BuddyPress 1.9.1. and i’ve traced it all from the template all the way down. :)

    Avatar of Boone Gorges
    Boone Gorges
    Keymaster

    @boonebgorges

    I guess the best way to do it would be to filter ‘bp_pre_user_query’ and do some manual modification to the uid_clauses['where'] SQL string.

    I know this is less than ideal. In the future, we’ll aim to have better sorting features in BP_Group_Member_Query. But it’s unlikely we could build a system that’d accommodate your custom usermeta sort, in any case, so you’re probably always going to have to do this manually. That said, having a filter on BP_Group_Member_Query::get_group_member_ids() or BP_Group_Member_Query::get_include_ids() is not a terrible idea. Feel free to open an enhancement ticket at http://buddypress.trac.wordpress.org.

    Avatar of shanebp
    shanebp
    Moderator

    @shanebp

    You don’t say if you’re doing this on a group page.
    Assuming you are…

    Find a hook prior to output of group users.

    Hook a function that contains your custom sql.

    Take a look at using the bp_pre_user_query_construct hook and ‘Preserve the Order’ here:
    http://codex.buddypress.org/developer/bp_user_query/#code-examples

    Avatar of Dimensionmedia
    David Bisset
    Participant

    @dimensionmedia

    Thanks guys. I’ll take a look at this today. Sorry for the late response. apparently the “notify me of follow ups replies via email” is taking a vacation.

    Avatar of Dimensionmedia
    David Bisset
    Participant

    @dimensionmedia

    Just for the record, I created the ticket: https://buddypress.trac.wordpress.org/ticket/5356#ticket

    Avatar of Dimensionmedia
    David Bisset
    Participant

    @dimensionmedia

    @shanebp – those examples and hooks don’t apply to group member pages (which you assumed correctly, that’s what i’m currently playing with).

    Avatar of Dimensionmedia
    David Bisset
    Participant

    @dimensionmedia

    Ok, you can’t mean edit BP Core… what exactly do you mean by manually?

    Avatar of shanebp
    shanebp
    Moderator

    @shanebp

    @dimensionmedia
    >those examples and hooks don’t apply to group member pages

    Yes they do.
    BP_Group_Member_Query extends BP_User_Query

    For example, say a member with id=2 belongs to a group.
    You can leave them on the main Members page but remove them from the group members page like so:

    function group_exclude_two( $query_array ) {
      $query_array->query_vars['exclude'] = 2;
    }
    
    function group_exclude_one() { 
      add_action( 'bp_pre_user_query_construct',  'group_exclude_two', 1, 1); 
    }
    add_action('bp_before_group_body', 'group_exclude_one'); 

    Of course the filter you request in that ticket would be very useful, thanks.

    Avatar of shanebp
    shanebp
    Moderator

    @shanebp

    When Boone says manually, he means use this hook…
    do_action_ref_array( 'bp_pre_user_query', array( &$this ) );

    …to call a function that you write that adjusts the ‘order’ and/or ‘orderby’ clauses.

    So now you have two paths for adjusting sort :)
    No need to edit core files.

    Avatar of Dimensionmedia
    David Bisset
    Participant

    @dimensionmedia

    Odd. I used the code you referred to in your first post and added a breakpoint. Saw the break on members directory but not on the group members page, which is why i concluded what i did.

    I’ll give your new example and the old one additional consideration though. Thank you VERY much for your reply and with any success, i’ll update this ticket.

    I personally hope my ticket request is considered though. :)

    Avatar of Dimensionmedia
    David Bisset
    Participant

    @dimensionmedia

    Awesome. Thanks for clearing that up. :)

    Avatar of shanebp
    shanebp
    Moderator

    @shanebp

    The example on the codex page uses this hook: bp_before_directory_members

    So you shouldn’t see it on a group members page.

    From the codex page:
    “It will not affect the display of members on pages like …/groups/some-group/members/ or in widgets, etc.”

    It’s a bit complex the first time you use member query hooks, but they are extremely useful.

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

You must be logged in to reply to this topic.