2

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; ?>

    </ul>

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

Addy
  • 998
  • 4
  • 12
  • 36

1 Answers1

1

It's a bit more complicated than you think.

bp_has_members() doesn't support getting users by role. But it supports getting users by their IDs. So the solution might be like this:

  1. Get array of IDs of users you need:

    $blogusers = get_users( 'fields=ID&role=author' );
    
  2. Instead of role=author add this string to bp_has_members() params:

    include='.implode(',', $blogusers)
    

Thus you will get users of your role.

Don't forget, that you can add ordering to get_users() and bp_has_members() call - that will reflect the order of users displayed on a page.

Slava Abakumov
  • 698
  • 6
  • 17
  • Also asked & answered here: http://wordpress.stackexchange.com/questions/196929/how-to-get-member-list-based-on-role-by-using-buddypress – shanebp Aug 09 '15 at 00:21