Hi,
I purchased your member types plugin because I need the directory to only show members, not all WordPress users. I don’t understand how to do this – can you help me?
In case it helps someone else:
For the time being, I added a WP role “Community Member”, linked it to the membership purchase, then added this code to functions so the directory only shows users with this role:/** * Exclude Users from BuddyPress Members List unless they have specific WordPress role. * * @param array $args args. * * @return array */ function buddydev_exclude_users_by_role( $args ) { // do not exclude in admin. if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { return $args; } $excluded = isset( $args['exclude'] ) ? $args['exclude'] : array(); if ( ! is_array( $excluded ) ) { $excluded = explode( ',', $excluded ); } $role = 'community_member';// change to the role to be shown. $user_ids = get_users( array( 'role__not_in' => $role, 'fields' => 'ID' ) ); $excluded = array_merge( $excluded, $user_ids ); $args['exclude'] = $excluded; return $args; } add_filter( 'bp_after_has_members_parse_args', 'buddydev_exclude_users_by_role' );
Hi Mathilde,
Welcome to BuddyDev forums.Thank you for using the plugin. Your approach of using a role is much better. Another solution is to exclude users without a member type(by setting member_type__in option). For now, I will suggest keep using it.
Regards
Brajesh
The topic ‘ [Resolved] How to exclude users without member type from directory’ is closed to new replies.