admin管理员组

文章数量:1134247

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.

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.

Share Improve this question edited Aug 8, 2015 at 1:09 fuxia 107k38 gold badges255 silver badges459 bronze badges asked Aug 7, 2015 at 6:24 AddyAddy 1761 silver badge9 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 3

To preserve pagination, try:

<?php    
$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) ) : ?>
//etc

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.

<?php 
   $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.

本文标签: pluginsHow to get member list based on role by using buddypress