I am new in buddypress.

My problem is: I have create a template for get member list based on role Like:

<?php if ( bp_has_members( bp_ajax_querystring( 'members' ). '&per_page=25&role=author' ) ) : ?>

    <ul id="members-list" class="item-list row kleo-isotope masonry">

      <?php while ( bp_members() ) : bp_the_member(); ?>
         <li><a href="<?php bp_member_permalink(); ?>"><?php bp_member_avatar(); ?></a></li>
      <?php endwhile; ?>


But i am not getting user list based on role. Please help me and suggest me any idea.

2 Answers 2


To preserve pagination, try:

$authors = get_users( array( 'fields' => 'ID', 'role' => 'author' ) );
$authors = implode(',', $authors);

<?php if ( bp_has_members( bp_ajax_querystring( 'members' ). '&per_page=25&include=' . $authors) ) : ?>

If you use this code directly below while ( bp_members() ) : bp_the_member(); in the members loop, you’ll be able to see which members are author.

   $user_id = bp_get_member_user_id(); 
   $user = new WP_User( $user_id );

   if ( $user->roles[0] == 'author' ) {
      echo 'this user is an author';

I know this isn’t exactly what you’d like to do but it should put you on the right track.

Note: This code assumes that all of your users have a single role assigned.

  • But this will create problem in paging. because paging is depend on how much user coming using query . By using your code i can skip only other user inside loop
    – Addy
    Aug 7, 2015 at 6:53
  • Create your custom function which help you to find this. Put the function get_custom_member() in your-theme/functions.php or in bp-custom.php. Why? So you can avoid using the $wpdb global in your template and the function will be available anywhere you have a member loop. Aug 7, 2015 at 8:20
  • OR pass user_id into bp_has_members(). $user_role = array ( 'role' => 'author', ); $all_authors = get_users ($user_role); $members_to_be_included = array (); foreach ($all_authors as $all_author) { $members_to_be_included[] = $all_author->ID; } Aug 7, 2015 at 8:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.