Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: [Resolved] How to create Loop from groups_get_user_groups output

@rogercoathup

Participant

For a loop like that you can use bp_has_groups() instead of groups_get_user_groups(). Is there a reason why you rejected that approach?

Then a my groups widget can have a simple core like this:


		<?php if ( bp_has_groups( 'type=alphabetical&user_id=' . bp_loggedin_user_id() ) ) : ?>

			<ul id="my-groups-list">
				<?php while ( bp_groups() ) : bp_the_group(); ?>
					<li class="row collapse">
						<div class="item-avatar small-3 columns">
							<a href="<?php bp_group_permalink() ?>"><?php bp_group_avatar_thumb() ?></a>
						</div>

						<div class="item small-9 columns">
							<div class="item-title"><a href="<?php bp_group_permalink() ?>" title="<?php bp_group_name() ?>"><?php bp_group_name() ?></a></div>
						</div>
					</li>
				<?php endwhile; ?>
			</ul>

		<?php else: ?>

			<div class="widget-error"><?php _e( 'No current groups.', 'my-groups-widget' ); ?></div>

		<?php endif; ?>

Note: If you want to use functions like bp_group_name(), you need to be inside a bp_has_groups() loop. The loop and bp_the_group() instantiate structures in the group template that are then used by bp_group_name.

If you want to use groups_get_user_groups() and setup your own loop, you’ll need to use different functions to access the name, permalink, etc. Look in bp-groups-functions.php, bp-groups-template.php and in bp-group-classes.php to get an idea what’s available.

Skip to toolbar