Skip to:
Content
Pages
Categories
Search
Top
Bottom

redirect buddypress groups page to forum page


  • Sherry22
    Participant

    @sherry22

    I would like to know how to redirect the groups page to the groups forum page regardless of what group a member is joined to.. ideas?

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

  • Henry Wright
    Moderator

    @henrywright

    Hi @sherry22

    You can redirect pages using the wp_redirect() function. For example:

    function my_redirect() {
        if ( bp_is_groups() && ! bp_is_group_forum() ) {
            wp_redirect( home_url() . '/whichever-page-you-want/' );
            exit;
        }
    }
    add_action( 'init', 'my_redirect' );

    Ref: https://codex.wordpress.org/Function_Reference/wp_redirect


    Sherry22
    Participant

    @sherry22

    Thanks for your reply here .. only problem is I can’t define a url because every member will be associated to a different forum.
    Any suggestions?


    shanebp
    Moderator

    @shanebp

    Can a user belong to more than one group?
    If not, try this (untested):

    
    function my_group_forum_redirect() {
    
        if ( bp_is_groups_directory() ) {
           
    	$user_id = get_current_user_id();
    	
    	$args = array(
    		'user_id'           => $user_id,
    		'populate_extras'   => false
    	);
    	
    	$groups = groups_get_groups( $args );
    	
    	$groups = $groups['groups'];
    		
    	$group_name = '';
    		
    	foreach( $groups as $group ) {
    		$group_name = $group->name;
    	}       
          
            if( $group_name != '' ) {
    	    wp_redirect( home_url() . '/groups/' . $group_name . '/forum/' );
                exit;
    	}
        }
    }
    add_action( 'init', 'my_group_forum_redirect' );
    

    Sherry22
    Participant

    @sherry22

    Thanks for getting back to me, I appreciate it 🙂
    The answer is each member will only below to 1 group.
    I added this code to the functions.php file but when I bring up my url/groups I still have to click on my group name to enter the forum.

    Any other thoughts?


    shanebp
    Moderator

    @shanebp

    My function was hooking too early.
    And using name instead of slug.

    Try:

    function my_group_forum_redirect() {
    
        if ( bp_is_groups_directory() ) {
           
    		$user_id = get_current_user_id();
    		
    		$args = array(
    			'user_id'           => $user_id,
    			'populate_extras'   => false
    		);
    		
    		$groups = groups_get_groups( $args );
    		
    		$groups = $groups['groups'];
    			
    		$group_slug = '';
    			
    		foreach( $groups as $group ) {
    			$group_slug = $group->slug;
    		}       
    	      
    		if( $group_slug != '' ) {
    			wp_redirect( home_url() . '/groups/' . $group_slug . '/forum/' );
    			exit;
    		}
        }
    }
    add_action( 'wp', 'my_group_forum_redirect' );

    Sherry22
    Participant

    @sherry22

    🙁 nothing changed still displays a list of the groups instead of linking to group forum.
    That being said the path I have on the post button is siteurl/groups
    I have attempted to put my-groups in the url but doesn’t work.

    Wonder if I am missing something. If you have a test site does this work for you when linking to a group? also to clarify I am adding this to theme function.php, is that the correct spot to add it.
    Thank you…


    shanebp
    Moderator

    @shanebp

    The function works on a test site when I go to home_url() . '/groups/'

    You may need to put it in bp-custom.php.


    Sherry22
    Participant

    @sherry22

    so you are redirected to your group forum where you see previous topics and can submit a new topic?

    I added the code [edited] in a file titled bp-custom.php and put in in my wp-contents/plugins/ folder and still when I click on siteurl/groups it just shows my group names which I still have to click.

    Any idea? Would it help to send my url offline?
    thanks …


    Sherry22
    Participant

    @sherry22

    I created a new group and it looks like it is working now.
    Thank you so much. I haven’t had much luck with answers on this forum until you replied.


    Sherry22
    Participant

    @sherry22

    Hi Shane, I have 1 more question for you 🙂

    I need the exact same function to redirect groups home activity page so that I can add something like this url siteurl/groups/home/ to a button on my site and this redirects members to their groups activity feed. or in the forum what is known as the home button.

    think you could help with my last request?


    Sherry22
    Participant

    @sherry22

    would I just change /home after groups/ and duplicate the function above?


    Peter Hardy-vanDoorn
    Participant

    @petervandoorn

    Since BP 1.6 there has been a constant that defines this.

    Just add define ( 'BP_GROUPS_DEFAULT_EXTENSION', 'forum' ); to your functions.php or bp-custom.php file.

    From then on, when you click to go to a group, it will display the group’s forum page instead of the normal ‘Home’ activity landing page.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘redirect buddypress groups page to forum page’ is closed to new replies.
Skip to toolbar