Group Mods

  • Profile picture of @mercime
  • Profile picture of r-a-y
  • Profile picture of Hugo

How to Exclude a Group From the Groups Loop (12 posts)

Started 1 year, 10 months ago by: Sarah Gooding

  • Profile picture of Sarah Gooding Sarah Gooding said 1 year, 10 months ago:

    Is there any way to exclude a group from the loop? I don’t see anything in the documentation. I can’t make it hidden or private because I’m using the group as a shell for a global forum. (Each member is automatically added to this group at registration) … so it’s always floating to the top as the most popular group since it has the most members. I tried using &exclude= and it doesn’t do anything. Any help is appreciated. Thanks!

  • Profile picture of Nahum Nahum said 1 year, 10 months ago:

    @pollyplummer r-a-y showed me how to do this for blogs, thought i’d flip it for the groups loop and it seems to work. this was from a couple versions back there may be something new as it was said there would be an easier exclude parameter for has_blogs but i haven’t seen it. anyway try

    php while ( bp_groups() ) : bp_the_group(); if(bp_get_group_name() != “Name of your Group”) :

    then add the ?php endif? before the endwhile.

  • Profile picture of Sarah Gooding Sarah Gooding said 1 year, 10 months ago:

    Thanks @nahummadrid ! This works:

    while ( bp_groups() ) : bp_the_group(); if(bp_get_group_name() != ‘MyGroup’ ) :

    I think I’ll post something about this on wpmu.org because it seems like a pretty common request. I wish there was some kind of exclude parameter instead. ;)

  • Profile picture of ch8rt ch8rt said 1 year, 10 months ago:

    I’m totally up on my php so could someone help with converting this into an ‘if’ ‘else’ statement that allows for multiple group names rather than just one.

    So far I’ve got this
    if(bp_get_group_name() != ‘Community’ ) : if(bp_get_group_name() != ‘General’ ) : if(bp_get_group_name() != ‘Off Topic’ ) :

    but I need to endif 3 times which surely isn’t the best way. And also I can get an else in there.

    To put some context around this, I plan on having a number of groups for forums only, and new members will automatically be added to them, so I plan on hiding the item-header and nav section on these group pages and show a new in there instead. Then when they are removed from the groups page and widgets they’ll only be accessible through the forums. :)

  • Profile picture of Hugo Hugo said 1 year, 10 months ago:

    You need ‘||’ ‘Or’ don’t you?

    so you want to run code if it’s not the community group or not the general group etc?

    if(bp_get_group_name() != ‘Community’ || bp_get_group_name() != ‘General’ ):

  • Profile picture of Roger Coathup Roger Coathup said 1 year, 8 months ago:

    @ch8rt – rather than write that long nested if structure, put your group names into an array, and then check if the bp_get_group_name is in that array, using the PHP in_array() function: http://php.net/manual/en/function.in-array.php

    @pollyplummer – Yes, an exclude parameter would be very useful – it came up in another forum thread recently as well

  • Profile picture of Boone Gorges Boone Gorges said 1 year, 8 months ago:

    I have grand designs of adding things like exclude parameters to all the bp_has_x loops. Now that the 1.2 branch has been merged into the trunk, I can have a swing at those designs :)

  • Profile picture of ch8rt ch8rt said 1 year, 8 months ago:

    I’m still trying to get this working, an array seems the best way, like you said, but I have no idea on how to code it properly. The documentation for php always seems to go over my head.

    This is what I have so far.

    <?php
    $special = array("General", "Community");
    if ( bp_get_group_name() == $special ) ?>
    		/*special group*/
    	<?php else; ?>
    		/*none special group*/
    <?php endif; ?>

    But thats not working. Any ideas?

  • Profile picture of Hugo Hugo said 1 year, 8 months ago:

    Where’s your in_array() ?

  • Profile picture of Hugo Hugo said 1 year, 8 months ago:

    PHP docs are fairly clear, but try this:

    $special = array("General", "Community");
    if (in_array( bp_get_group_name(), $special) ) : ?>
    	<p>Do stuff if group name is in array</p>
    <?php else : ?>
    	<p>Otherwise do some different  stuff</p>
    <?php endif; ?>
  • Profile picture of ch8rt ch8rt said 1 year, 8 months ago:

    Yep, works a charm. Big Thanks.

    I wasn’t getting anything with the in_array (must’ve had brackets in the wrong place or something) and then started thinking that the array call in the function up top would do that bit?

    Again, thanks.

  • Profile picture of volpv volpv said 5 months, 1 week ago:

    Hi @boonebgorges can we specify the exclude bp_has_group parameters in widget_logic for excluding some groups from getting displayed?

    Appreciate your help. Thank you