Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Network Wide BuddyPress w/ Site Specific Groups


  • Christian Freeman (codelion)
    Participant

    @takinglife2themax

    Hi guys,
    I’ve got a WordPress 3.8.1 Multisite install with BuddyPress 1.9.1 network activated. My goal is to have ALL BuddyPress components globally activated (shared among all of my network subsites) EXCEPT for the Groups component.

    I need to display ONLY the groups that were created on that particular site. So if I create a group on my Support Site, only the groups that I’ve created on the Support Site will be displayed on the Groups List (groups-loop).

    I noticed that someone else created some functions for this, but it only worked for Buddypress 1.5 and earlier:

    Any suggestions on how I can update this code for the newer BuddyPress 1.9.1?

    Thanks

Viewing 1 replies (of 1 total)

  • Christian Freeman (codelion)
    Participant

    @takinglife2themax

    Ok nevermind,
    I was able to fix a few syntax errors and get this working. Here’s the code:

    bp-custom

    // Add meta fields upon group creation
    function bp_group_meta_save ( $group_id ) {
    	$blog = get_blog_details( get_current_blog_id(), true );
    	
    	$fields = array(
    	'blog_id' => $blog->blog_id,
    	'blog_path' => $blog->path,
    	'blog_name' => $blog->blogname
    	);
    	
    	foreach ( $fields as $field => $value ) {
    	groups_update_groupmeta( $group_id, $field, $value );
    	}
    }
    add_action( 'groups_created_group', 'bp_group_meta_save' );
    
    function get_groups_by_meta ( $field, $meta_key, $meta_value ) {
    	global $wpdb;
    	
    	if ( is_string( $meta_value) ) $meta_value = "'" . $meta_value . "'";
    	
    	$sql = $wpdb->prepare( "SELECT $field from {$wpdb->base_prefix}bp_groups_groupmeta WHERE meta_key='$meta_key' AND meta_value=$meta_value", OBJECT );
    	$res = $wpdb->get_results( $sql );
    	
    	return $res;
    }
    
    // Build a list of groups with the matching blog_id value
    function get_groups_by_blogid ( $blog_id = 1 ) {
    	$list = get_groups_by_meta( 'group_id', 'blog_id', $blog_id );
    	
    	if ( count( $list ) ) {
    	$res = "";
    	foreach ( $list as $item ) {
    	$res .= $item->group_id . ',';
    	}
    	return substr( $res, 0, -1);
    	} else {
    	return FALSE;
    	}
    }

    groups-loop

    <?php 
    $current_blogid = get_current_blog_id();
    
    if ( $current_blogid > 1) {
    $groups_set = get_groups_by_blogid( $current_blogid );
    ( $groups_set !== FALSE ) ? $extra_args = '&include=' . $groups_set : $extra_args = '&include=-1';
    }
    
    if ( bp_has_groups( bp_ajax_querystring( 'groups' ) . $extra_args ) ) : ?>

    Thanks again to @juanlopez4691

Viewing 1 replies (of 1 total)
  • The topic ‘[Resolved] Network Wide BuddyPress w/ Site Specific Groups’ is closed to new replies.
Skip to toolbar