How to query the list of user with a specific membership ?

Hi,

I'd like to show a list of member with specific membership.
How can i query it ?

Thanks for your help.

  • Kris Tomczyk

    Hi Imad,

    Hope you are doing good today.

    I am afraid we don't have members listing option in Membership 2 Pro. You would need to make some customizations to make this work.

    However, Membership 2 Pro plugin can be integrated with BuddyPress seamlessly. In BuddyPress you can go to Settings > BuddyPress > Pages tab and there select page where to show all your members. But adding additional filter would also require some advanced customization.

    In this case you can also use our Job Portal where experience WordPress developers from community work.
    https://premium.wpmudev.org/wordpress-development/

    Kind Regards,
    Kris

  • Kris Tomczyk

    Hi Imad,

    I asked my colleagues from WPMU support staff and they suggested me the perfect solution for you.

    In your theme find a functions.php file. Add this code:

    add_shortcode( 'show_members', 'show_members_cb' );
    function show_members_cb( $atts ) {
        $atts = shortcode_atts(
            array(
                'id' => 0
            ),
            $atts
        );
        if( $atts['id'] == 0 ) {
            return 'You need to provide a membership ID';
        }
        $args = array(
            'membership_id' => $atts['id'],
            'subscription_status' => 'active'
        );
        $members = MS_Model_Member::get_members( $args );
        $html = '<table cellpadding="5" cellspacing="5">';
            $html .= '<tr>';
                $html .= '<th>User ID</th>';
                $html .= '<th>Username</th>';
                $html .= '<th>Display Name</th>';
            $html .= '</tr>';
        foreach( $members as $member ) {
            $html .= '<tr>';
                $html .= '<td>' . $member->id . '</td>';
                $html .= '<td>' . $member->username . '</td>';
                $html .= '<td>' . $member->name . '</td>';
            $html .= '</tr>';
        }
        $html .= '</table>';
        return $html;
    }

    You can remove unnecessary columns if you need it. For example, you do not want the "User ID" column, so you are removing the code from the above code:

    $html .= '<th>User ID</th>';
    and
    $html .= '<td>' . $member->id . '</td>';
    See the screenshot:

    After that make a page with this shortcode:

    [show_members id="XX"]
    where instead XX just put your membership ID. To get your membership ID go to:
    Membership 2 -> Memberships and look at the end of table, there is a shortcode column, hover on "SHOW" button and you will see ID of selected Membership.

    I made a test on my site and it works great. Here is a proof:

    Let me know in response.

    Kind Regards,
    Kris

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.