How to make a list of members in Buddypress

Hi
I have two types of profiles in buddypress - mentors and users. How do I generate a page that just shows the mentors and their buddypress profiles?
This is supposed to be built in in buddypress latest version

  • Patrick
    • Support Monkey

    Hi there @michael

    I hope you're having a great day!

    Indeed, the functionality is built into the latest BuddyPress. But creating directories for specific member types must be done manually, as there is as yet no interface for that in the plugin.

    Basically, you just need to add a new argument to the functions that create your member types:
    'has_directory' => 'custom-name'

    See this page in the BuddyPress codex for details:
    https://codex.buddypress.org/developer/member-types/

    I hope this helps! And thanks for being a member :slight_smile:

  • michael
    • The Incredible Code Injector

    The site is caregivermentors.com - there are two types of members - caregivers and mentors
    can you please give me the code and tell me where to paste it for creating a page of just mentors and have it searchable?

    I saw the codex but did not understand it at all and still don't
    Thanks

  • Sajid
    • DEV MAN’s Sidekick

    Hi @michael

    Hope you are doing good today :slight_smile:

    Please post the code that you used to create members types.

    It should look like this.

    function bbg_register_member_types_with_directory() {
        bp_register_member_type( 'mentors', array(
            'labels' => array(
                'name'          => 'Mentors',
                'singular_name' => 'Mentor',
            )
        ) );
    }
    add_action( 'bp_register_member_types', 'bbg_register_member_types_with_directory' );

    You can then specify the slug in "has_directory" parameter.

    If you are not sure where is that code. Then please contact your developer who added the members type support. We must find that code in order to make it search able.

    Also have you tried to search it like this. This is how it suppose to index if configured correctly.
    caregivermentors.com/members/type/caregivers
    caregivermentors.com/members/type/mentors

    Look forward towards your response :slight_smile:

    Cheers, Sajid

  • michael
    • The Incredible Code Injector

    ok, so if I add the above code to my child theme functions php and then create a link called:
    caregivermentors.com/members/type/mentors - it will take me to a page with all of the mentors
    1. is that correct?
    2. where exactly do I paste in the php
    3. do I need to do anything else
    thanks

  • Sajid
    • DEV MAN’s Sidekick

    Hi @michael

    Hope you are doing good today :slight_smile:

    I wrote a tiny plugin for you to add member types and set those types to your members. Download the attached and install it like normal WP plugin.

    Here is what it will do:

    1. Will create two member types "Caregivers" and "Mentors".
    2. Set these types to members using their ID.

    To assign your members you need to add coma separated user IDs in $mentors and $caregivers array, in bp_members_types.php file of this plugin. In below code 1, 2,3 are user IDs for mentors and 4,5,6 user IDs of caregivers. You can find user ID in Admin > Users > Edit URL (see screenshot).

    $mentors = array(1,2,3);
    $caregivers = array(4,5,6);

    You can also change the labels according to your requirements.

    Take care and have a nice day :slight_smile:

    Cheers, Sajid

  • Sajid
    • DEV MAN’s Sidekick

    Hi @michael

    Hope you are doing good and you are welcome :slight_smile:

    You have to edit bp_members_types.php file and change the name of existing type with new one for your other sites. Make a copy of this plugin for your other site (do not edit it directly).

    Here I updated the code according to your new requirements. Replace entire code in bp_members_types.php file with below code.

    function bbg_register_member_types_with_directory() {
        bp_register_member_type( 'expert', array(
            'labels' => array(
                'name'          => 'Experts',
                'singular_name' => 'Expert',
            ),
            'has_directory' => 'experts'
        ) );
    
    	 bp_register_member_type( 'user', array(
            'labels' => array(
               'name'          => 'Users',
               'singular_name' => 'User',
            ),
            'has_directory' => 'users'
        ) );
    }
    add_action( 'bp_register_member_types', 'bbg_register_member_types_with_directory' );
    
    function setmember_type(){
    	$mentors = array(1,2,3);
     	if($mentors ){
    		foreach($mentors as $mentor_id){
    			$member_type = bp_set_member_type( $mentor_id, 'expert' );
    		}
    	}
    
    	$caregivers = array(4,5,6);
    	if($caregivers ){
    		foreach($caregivers as $caregiver_id){
    			$member_type = bp_set_member_type( $caregiver_id, 'function bbg_register_member_types_with_directory() {
        bp_register_member_type( 'expert', array(
            'labels' => array(
                'name'          => 'Experts',
                'singular_name' => 'Expert',
            ),
            'has_directory' => 'experts'
        ) );
    
    	 bp_register_member_type( 'user', array(
            'labels' => array(
               'name'          => 'Users',
               'singular_name' => 'User',
            ),
            'has_directory' => 'users'
        ) );
    }
    add_action( 'bp_register_member_types', 'bbg_register_member_types_with_directory' );
    
    function setmember_type(){
    	$mentors = array(1,2,3);
     	if($mentors ){
    		foreach($mentors as $mentor_id){
    			$member_type = bp_set_member_type( $mentor_id, 'expert' );
    		}
    	}
    
    	$caregivers = array(4,5,6);
    	if($caregivers ){
    		foreach($caregivers as $caregiver_id){
    			$member_type = bp_set_member_type( $caregiver_id, 'user' );
    		}
    	}
    
    	$gmember_type = bp_get_member_type( 1 );
    }
    
    add_action('bp_init', 'setmember_type');' );
    		}
    	}
    
    	$gmember_type = bp_get_member_type( 1 );
    }
    
    add_action('bp_init', 'setmember_type');

    The most important part of this plugin is member types slug (expert, user). The must be unique while registering and must be same when you will set types in second function of this plugin.

    Hope it helps :slight_smile:

    Cheers, Sajid

  • michael
    • The Incredible Code Injector

    I really really appreciate all your work - but I expect to have thousands of mentors and I cannot manually add them as you suggest. I know buddypress has a built in solution to create members and we need to please us it
    thanks

  • Patrick
    • Support Monkey

    Hi there @michael

    I hope you're well today!

    The code provided by @Sajid should indeed register custom member types. It also provides a way for you to assign those member types in the code to selected users.

    However, the member-type functionality is brand-new in BuddyPress and is limited to simply allowing you to create different member types, assign users to them manually or programatically as above, and have specific directories for each member type.

    If you want users to be able to select the member type when they signup on your site, and/or have specific x-profile fields that only appear for certain member types, then you're going to have to code those features yourself.

    Fortunately though, others have asked for the same things, and a few kind souls have provided solutions.

    To create the member types and a nice tabbed directory, as well as an x-profile field where users can select the member type themselves:
    https://buddypress.org/support/topic/2-2-member-types-setting-user-member-types-during-registration-xprofile/#post-239561

    A nifty plugin to enable you to conditionally set x-profile fields to show only for certain member types:
    https://github.com/lmoffereins/bp-xprofile-field-for-member-types

  • Sajid
    • DEV MAN’s Sidekick

    Hi @michael

    Hope you are doing good today :slight_smile:

    I have not used that plugin and not sure how that will work.

    If you want your uses to be able to select member type on registration then we can do that as well.

    Enable Extended Profile Component, create a xprofile field form Admin > Users > Profile Fields (Select/Dropdown) with options "Mentors", "Caregiver". Then post the ID or name of this field here and I will give you updated code to make it work. This way you do not need to manually have the IDs of user, updating the code and assigning them member type.

    Take care and have a nice day :slight_smile:

    Cheers, Sajid

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.