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. π
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.
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:
https://codex.buddypress.org/developer/bp_user_query/#code-examples
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.
@shanebp – those examples and hooks don’t apply to group member pages (which you assumed correctly, that’s what i’m currently playing with).
Ok, you can’t mean edit BP Core… what exactly do you mean by manually?
@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.
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.
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. π
Awesome. Thanks for clearing that up. π
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.