Skip to:
Content
Pages
Categories
Search
Top
Bottom

Add new field to buddypress member search form


  • pokhsujan
    Participant

    @pokhsujan

    Hi all,

    Is there any way to add the extra fields to the buddypress member search form.
    What I want is to add a new field called User role in a dropdown and when selecting the dropdown, only the users with the selected role should be listed in the members page.
    Currently, I have been able to add the field using buddypress filter hook bp_directory_members_search_form . But, I don’t know how to handle that new fields because while clicking the submit button in the form, currently it runs ajax and only the default (previous) field i.e. the member name field seems to be posted.
    I can also change the members loop function

    if(bp_has_members( bp_ajax_querystring( ‘members’ )

    with my custom conditions by adding the ids in include parameters. But, I have not been able to find what is submitted in the role field from my form.
    So, I want to know what is submitted from the newly added field in member-loop.php file.

    Please help,
    Note, I don’t want to use any other plugins for this task.

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

  • danbp
    Moderator

    @danbp

    If you use custom “roles”, aka member types (not WP roles) see here:

    Member Types

    When you follow the tuto, you will have an All members directory and on separate tabs, all Teachers and all Students. As the search filter is contextual (so far i remember), you can search each tab by context.

    If this is ok for you, you can then remove the all Member tab which is hardcoded on the Member Directory template (child-theme/buddypress/members/index.php)


    pokhsujan
    Participant

    @pokhsujan

    Sorry if I could’nt illustrate my problem clearly.
    I already have assigned user roles/ types for all users. What I need is to find the submitted value from the buddypress member search that I have added.
    If I could find the submitted value I could solve my problem.
    Currently, I have added an extra field in my buddypress Member search form and when I submit it, I could see the other fields have been submitted through ajax while my new field data is not submitted.
    here is the hook I used to add the new field.
    add_filter( ‘bp_directory_members_search_form’, ‘role_based_filter’, 10, 1 );
    function role_based_filter($search_form_html){
    $query_arg = bp_core_get_component_search_query_arg( ‘members’ );
    // echo ‘query args is’ . $query_arg;

    if ( ! empty( $_REQUEST[ $query_arg ] ) ) {
    $search_value = stripslashes( $_REQUEST[ $query_arg ] );
    } else {
    $search_value = bp_get_search_default_text( ‘members’ );
    }
    // echo ‘submitted is ‘ . $_REQUEST[ $query_arg ];
    $user_content = get_users_content();
    $roles = $user_content[‘roles’];
    $search_form_html = ‘<form action=”” method=”get” id=”search-members-form”>
    <label for=”members_search”><input type=”text” name=”‘ . esc_attr( $query_arg ) . ‘” id=”members_search” placeholder=”‘. esc_attr( $search_value ) .'” /></label><label for=”members-role”><select name=”members_role” id=”members-role”><option value=””> Role </option>’;
    foreach ($roles as $key => $role) {
    $search_form_html .= ‘<option value=”‘.$role.'”>’.$role.'</option>’;
    }
    $search_form_html .= ‘</select></label>
    <input type=”submit” id=”members_search_submit” name=”members_search_submit” value=”‘ . __( ‘Search’, ‘buddypress’ ) . ‘” />
    </form>’;
    return $search_form_html;
    }

    where, get_users_content is my custom function to get all the user’s role and ids.


    pokhsujan
    Participant

    @pokhsujan

    Anyone ?
    Please Help


    melissacrokis
    Participant

    @melissacrokis

    Hi, could you resolve it? I’m trying to add a username field to member search…

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