BuddyDev

Search

[Resolved] Redirection to Buddypress Profile using Query Strings

  • Participant
    Level: Enlightened
    Posts: 83
    Princy Cromacio on #42265

    Hi There,
    Can I Redirect A Page having Query Strings including User ID to their Respective Buddypress Profile Pages?
    What I mean is Like Redirecting example.com/profile/?id=187 to Their Respective Buddypress profile Page?
    If The User ID 187 Belongs to John, the Page will be Redirected to example.com/members/john/ ?

    Thank You,
    Cromacio

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2398
    Ravi on #42270

    Hello Princy,

    Thank you for posting. Please try the following code it will redirect to user profile based on user_id in the query string.

    
    
    add_action( 'bp_template_redirect', function () {
    	$user_id = empty( $_GET['user_id'] ) ? '' : wp_unslash( $_GET['user_id'] );
    
    	$user = get_user_by( 'id', $user_id );
    
    	if ( ! $user ) {
    		return;
    	}
    
    	bp_core_redirect( bp_core_get_user_domain( $user->ID ) );
    } );
    
    

    Please let me know if it helps or not.

    Regards
    Ravi

  • Participant
    Level: Enlightened
    Posts: 83
    Princy Cromacio on #42271

    Hi Ravi,
    Thanks for Reply.

    Unfortunately, that Didn’t Work.
    Would Using Cloudflare Caching Cause an Issue? As that Adds Another Query String?
    If Not, The Complete Permalink, I’m Trying to Work with is This – /profile/?uid=29&swcfpc=1

    Thank You 🙂
    Cromacio

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2398
    Ravi on #42274

    Hello Princy,

    Please replace ‘user_id’ with ‘uid’ in the code mentioned above and Give it a try.

    If still not works, please share the code you are using and point me to the site link.

    Regards
    Ravi

  • Participant
    Level: Enlightened
    Posts: 83
    Princy Cromacio on #42278

    Thanks You Ravi,
    Worked 🙂

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2398
    Ravi on #42291

    Hello Princy

    Thank you for the acknowledgment. I am glad that I could help.

    Regards
    Ravi

The topic ‘ [Resolved] Redirection to Buddypress Profile using Query Strings’ is closed to new replies.

This topic is: resolved