Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: Show content for specific BP Groups only

@iuriem

Participant

This is what I use now. Try it:

/**
 * Show content only to group members
 * Author: Iurie Malai
 */

add_shortcode( 'group', 'group_check_shortcode' );
// usage: [group id = YOUR_GROUP_ID_HERE] content [/group]

function group_check_shortcode( $atts, $content = null ) {
	extract(shortcode_atts(array( 'id' => '', ), $atts));
	if( groups_is_user_member( bp_loggedin_user_id(), $id ) ) { return do_shortcode( $content ); }
	if( $id == 1 ) {
		return '<p>This will be seen only by logged in members of group with id = 1. In my case this is the group with all members of my site</p>';
	} else { 
		$group = groups_get_group( array( 'group_id' => $id ) );
		//Put your User Groups Page Slug in the next code row.
		//Usually this is "groups", but in my case it is different.
		$url = home_url( $path = 'USER_GROUPS_PAGE_SLUG_HERE/' . $group->slug . '/', $scheme = relative );
		return '<p>This will be seen only by logged in members of group with id that you specified by shortcode in your page or post. This will show the group name: <a href="' . $url . '">' .  $group->name . '</a>.</p>' ; }
} /*---------------------------------------------------------*/
Skip to toolbar