BuddyDev

Search

[Resolved] Multiple Member Types in same directory

  • Participant
    Level: Enlightened
    Posts: 34
    Joss Luberia on #21624

    Hi Brajesh,

    I don’t have any reply from you…

    Can you help me for this ?

    Thanks a lot,
    Joss

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #21639

    Hi Joss,
    I am sorry, I am looking for this ID
    https://i.imgur.com/LeiiJ3f.png

    I will need it to assist you. You mentioned the lables for membership. Can you please tell me the numeric ids?

    Thank you
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 34
    Joss Luberia on #21832

    Hi Brajesh,

    I’m sorry, I don’t have any email notification for your reply…

    The ID is number 2.

    Thank you very much for your help !
    Joss

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #21876

    Hi Joss,
    Thank you.

    Please use the updated code as

    
    
    function buddydev_show_pmpro_membership_level_in_dir() {
    	if ( ! bp_is_members_directory() ) {
    		return;
    	}
    	// for the logged in user.
    	$level = pmpro_getMembershipLevelForUser( bp_get_member_user_id() );
    
    	if ( ! $level || $level->id != 2 ) {
    		return;
    	}
    
    	echo '<div class="bp-member-xprofile-custom-field bp-member-level">' . $level->name . '</div>';
    }
    
    add_action( 'gwangi_buddypress_member_xprofile_custom_fields', 'buddydev_show_pmpro_membership_level_in_dir', 10 );
    
    

    Note the small change from earlier is this

    
    if ( ! $level || $level->id != 2 ) {
    		return;
    	}
    

    Hope this helps.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 34
    Joss Luberia on #21892

    You are the BEST Brajesh !!

    Thank you very much for your help !

    Just a last question : if I want to display one more level, how can I do this ?

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #21894

    Thank you for the kind words Joss.

    We can modify the above code like this

    
    function buddydev_show_pmpro_membership_level_in_dir() {
    	if ( ! bp_is_members_directory() ) {
    		return;
    	}
    	// for the logged in user.
    	$level = pmpro_getMembershipLevelForUser( bp_get_member_user_id() );
    	// please update with visible level ids.
    	$visible_level_ids = array( 1, 2 );
    
    	if ( ! $level || ! in_array( $level->id, $visible_level_ids ) ) {
    		return;
    	}
    
    	echo '<div class="bp-member-xprofile-custom-field bp-member-level">' . $level->name . '</div>';
    }
    
    add_action( 'gwangi_buddypress_member_xprofile_custom_fields', 'buddydev_show_pmpro_membership_level_in_dir', 10 );
    
    

    Please update the visible level ids with actual ids.

    Let me know if it works for you or not?

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 34
    Joss Luberia on #21902

    Thnks thanks thanks Brajesh !!

    I should really learn PHP code.

    Thank you for all your help,

    Best,
    Joss

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #21903

    You are welcome Joss.

    Learning is always beneficial 🙂

    Best regards
    Brajesh

The topic ‘ [Resolved] Multiple Member Types in same directory’ is closed to new replies.

This topic is: resolved