OK, I figured out a fix. I’ve added do_action(‘bp_before_members_loop’) at the point when the arguments are unserialised in bps_set_cookie (line 17 of bps-search.php), and this works. But I need to have the filter removed once it’s done.
Where should I put do_action(‘bp_after_members_loop’)?
OK, I debugged the functions bps_add_filter and bps_remove_filter and neither of them get executed when it’s an AJAX request, even though they do get added. Which makes me think that the bp_before_members_loop and bp_after_members_loop hooks aren’t executing on AJAX calls.
I’m not really sure what you’re suggesting, that’s just to ensure the filter doesn’t apply to any member loops after the search. As a test I tried commenting it out but it made no difference.