Display membership label on member list page

Hey i have a custom page displaying all my members and i want to display their membership level label next to their name.

I use a query to catch my members, something like this

if (!empty($users)) : foreach ( $users as $user ) : $userdata = get_userdata( $user->ID ); $resume_attach_id = get_user_meta($user->ID, 'resume_attach_id', true); $resume_url = wp_get_attachment_url( $resume_attach_id ); $resume_title = get_the_title($resume_attach_id); $street_address = get_user_meta($user->ID, 'street_address', true); $postal_code = get_user_meta($user->ID, 'postal_code', true); $city = get_user_meta($user->ID, 'city', true); $google = get_user_meta($user->ID, 'googleplus', true); $linkedin = get_user_meta($user->ID, 'linkedin', true); $facebook = get_user_meta($user->ID, 'facebook', true); $skype = get_user_meta($user->ID, 'skype', true);

I’ve read the documentation on how to display a membership label with the “S2MEMBER_CURRENT_USER_ACCESS_LABEL” but of course it not apply for this case because it actually display my membership label as loggedin user.

Does anyone can explain me how to display the level for each of my members on the list ? is there something to do with the get_userdata function on WP ? thanks for your help

Edit : i found the following function “get_user_field (“s2member_access_label”)” but it return my loggedin level instead of the member level on the list.

If you have Pro, you can just customize the [s2Member-List /] shortcode. See this and this.

Try this:

    $user_caps = $user->caps;
    foreach($user_caps as $ccap => $v) {
        if(preg_match('/^(subscriber)$/', $ccap, $m) or preg_match('/^s2member_(level.*)$/', $ccap, $m)) {
            $level = $m[1];
        }
    }

Then $level should be user’s level, or “subscriber” for L0.