Skip to:
Content
Pages
Categories
Search
Top
Bottom

Custom loop for Groups Member Directories


  • lesanis
    Participant

    @lesanis

    Hello,

    I run a site with subscriptions and I have spent a lot of time trying to create custom directories for groups that will be displaying users of specific roles but the issue is that by modifying
    <?php while ( bp_group_members() ) : bp_group_the_member(); ?>
    pagination shows count of all the members of the group and threre are a lot of blank pages with no members in them. So I ended using the following code before the creation of pagination.

    <?php $included_users = implode(',',get_users('role=subscriber&fields=ID')); ?>
    <?php d($included_users); ?>
    <?php //if ( bp_has_members( 'include=' . $included_users ) ) : ?>
    <?php if ( bp_has_members( bp_ajax_querystring( 'members' ) .'&include=' .$included_users ) ) : ?>
    <?php //if ( bp_group_has_members( bp_ajax_querystring( 'group_members' ).'&type=alphabetical' ) ) : ?>
    
    

    Now the issue is that group pages break and appears no members at all,no sidebars,nothing… Could anybody help please?? Is there sth wrong with that code?

    Thank you!!

Viewing 10 replies - 1 through 10 (of 10 total)

  • shanebp
    Moderator

    @shanebp

    What is this supposed to do? d($included_users);

    If you want group members, you need to use bp_group_has_members not bp_has_members.

    Turn on debugging while you trouble-shoot your code.


    lesanis
    Participant

    @lesanis

    Hello shanebp,

    Thank you for your response! I do not know what d($included_users); does. I just found the code from an old thread. I modified it after your reccommendation to

    
    <?php $included_users = implode(',',get_users('role=subscriber&fields=ID')); ?>
    
    <?php if ( bp_group_has_members( bp_ajax_querystring( 'group_members' ) .'&include=' .$included_users ) ) : ?>

    After that change the page is not breaking but the code does not work at all to filter the members.. Is there anything else that you think I should change?

    Thank you!!


    shanebp
    Moderator

    @shanebp

    bp_group_has_members does not have an include argument.
    It does have an exclude argument.

    More info:
    http://buddypress.wp-a2z.org/oik_api/bp_group_has_members/


    lesanis
    Participant

    @lesanis

    I don’t believe it, it worked!!! I have spent a lot of time trying to achieve that, thank you so so so much shanebp!!!!!!!!! Is there a way to modify
    get_users('role=subscriber&fields=ID'));
    so more than one roles can be excluded?


    shanebp
    Moderator

    @shanebp


    lesanis
    Participant

    @lesanis

    Thank you shanebp, I tried

    
    <?php $excluded_users = implode(',',get_users('role_in=array('administrator','subscriber','customer')&fields=ID')); ?>

    and with double quotes

    
    <?php $excluded_users = implode(',',get_users("role_in=array('administrator','subscriber','customer')&fields=ID")); ?>

    but now no members appear in the directories at all. What do you think is the mistake?


    shanebp
    Moderator

    @shanebp

    it’s role__in – not role_in


    lesanis
    Participant

    @lesanis

    The code I have now is

    
    <?php $excluded_users = implode(',',get_users("role__in=array('administrator','subscriber','customer')&fields=ID")); ?>
    
    <?php if ( bp_group_has_members( bp_ajax_querystring( 'group_members' ) .'&exclude=' .$excluded_users ) ) : ?>

    but no user is excluded. Isn’t that code right?


    shanebp
    Moderator

    @shanebp

    You need to learn the difference, in any coding lang, between strings and variables.

    $excluded_roles = array('administrator','subscriber','customer');
    $excluded_args = array(
    	'role__in'     => $excluded_roles,
    	'fields'       => 'ID',
     ); 
    $excluded_users = get_users( $excluded_args );
    $excluded_users = implode(',', $excluded_users);

    lesanis
    Participant

    @lesanis

    I have no words… thank you so so much shanebp!!!! You opened my eyes!!

Viewing 10 replies - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.
Skip to toolbar