I'm trying to pull a list of members who are attached to a certain subscription. The website is a sort of member directory, but there are other members who shouldn't be shown in this directory.
I can't find any documentation on pulling members based on a membership type - or much developer-based documentation at all to be honest.
The code I have currently is as follows:
<?php $args = array ( array( 'role' => 'Subscriber' ) ); $user_query = new WP_User_Query( $args ); $members = $user_query->get_results(); if (!empty($members)): ?> <?php foreach ($members as $member): ?> <?php // get all the user's data $member_info = get_userdata($member->ID); echo '<li>' . $member_info->first_name . ' ' . $member_info->last_name . '</li>'; ?> <?php endforeach; ?> <?php else: ?> Sorry, there were no members matching your search. <?php endif; ?>
I'm looking to expand this to only query users of the membership roles 'company' and 'member', and then to add some additional parameters based on custom fields attached.
Any help is massively appreciated.