• Participant
    Level: Initiated
    Posts: 2
    Melanie on #51681

    Hi Ravi, sure no worries 😉

    FYI, I tried a bit more things. I told you that I added the additional filter to the filter dropdown (recently active, newest and alphabetical) via: bp_members_directory_order_options

    I also tried to add it the same way as a tab instead like you add the tabs for “Featured Members” or “Recent Visitors” via: bp_members_directory_member_types

    All I want is this: have a new filter option to additionally filter the results. So lets say I check the Recent visitor or featured members tabs and see the results. They are not filtered yet, random, they show all members falling into the category (so either featured members or recent visitor based on what tab I selected).

    Now I want to filter them on top, to show for example only those whose name starts with an “A” as I previously mentioned. But this is where I am lost.

    I tried to hook into several options: bp_before_directory_members_content, bp_after_directory_members_content, bp_after_has_members_parse_args, bp_after_members_loop, etc but nothing worked.

  • Participant
    Level: Initiated
    Posts: 2
    Melanie on #51660

    Hi Ravi,
    sorry seems my 2nd message with the code did not get sent.
    Yes, these filter options are the native filter options we get:
    ‘active’, ‘random’, ‘newest’, ‘online’ and ‘alphabetical’.
    What I tried to achieve was to add a new one. Or if its not possible to add a new filter option in this dropdown I would also be happy to show it as a tab (next to “All Members”, “Recent Visitors” or “Featured Members” tabs) on the members page.

    But lets go back to what I was trying to do. So I added a filter option into the dropdown to the others:

    ` // Function to add the “Only A” filter option
    function add_only_a_filter() {
    <option value=”only_a”><?php _e( ‘Only A’, ‘buddypress’ ); ?></option>

    // Hook to add the “Only A” filter option to the Members directory order options
    add_action( ‘bp_members_directory_order_options’, ‘add_only_a_filter’ ); `

    The new filter option called “only A” shows up in the dropdown, so far so good. It is supposed to filter the results of any other search be it All Members, BP Search form results or even the Recent Visitor or Featured Member results to show only users whose name starts with an “A”.

    The filter shows up inside the dropdown but when I try to add a logic, it automatically filters alphabetically rather than showing me only those members whose name starts with an “A”.

     // Function to modify the members query based on the selected filter
    function modify_members_query_for_only_a( $query_args ) {
        if ( isset( $_GET['members_filter'] ) && $_GET['members_filter'] === 'only_a' ) {
            $query_args['field_id'] = '1'; // Adjust 'field_1' to the actual first name field key
            $query_args['meta_value'] = 'A%';
        return $query_args;
    // Hook to apply the filter to the members query
    add_filter( 'bp_after_has_members_parse_args', 'modify_members_query_for_only_a' ); 

    The field ID 1 is the First name field that I want to check who starts with “A”.
    I read in some of BuddyDevs older posts that its a good idea to hook into “‘bp_after_has_members_parse_args'” – which is what I was trying to do. I was hoping that by adding this filter logic the new filter option would show me users whose name starts with “A”.

    If this approach does not work, is there any way to add a separate tab maybe that might let me filter the results for other thiings than just alphabetical or recently active etc?

    Thanks again, Ravi 😉