BuddyDev

Search

[Resolved] Link to the group in the text of the post

  • Participant
    Level: Enlightened
    Posts: 33
    Vlad on #42926

    Hello, friends!

    I use your great plugins plugins.
    Blog Categories For Groups – https://buddydev.com/plugins/blog-categories-for-groups/
    BuddyPress Simple Front End Post – https://buddydev.com/plugins/bp-simple-front-end-post/

    Is it possible to add a link to the group in the text of the post,
    under the caption of the post or at the end of the post.

    Thanks for helping!

  • Participant
    Level: Enlightened
    Posts: 33
    Vlad on #42927

    I added a link but it only shows up in the group
    <p><?php echo bp_group_link(); ?></p>

    how to make the link appear everywhere and in the general blog of the site

    • This reply was modified 2 years, 9 months ago by Vlad.
  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #42955

    Hi Vald,
    Thank you for using the plugins.

    We do keep the group ids with the post which can be accessed using the following code

    
    $group_id = get_post_meta( $post_id, '_bcg_group_id', true );
    

    I am requesting Ravi to assist you with further code.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 33
    Vlad on #42961

    Hi Brajesh,

    thanks for the tip, searched on the internet,
    was able to output as an object, did it


    $post_id = get_the_ID();

    $group_id = get_post_meta( $post_id, ‘_bcg_group_id’, true );

    $group_obj = groups_get_group ( $group_id );

    $href = bp_get_group_permalink( $group_obj );

    ?>
    Author: *a href=”<?php echo $href;?>”><?php echo bp_group_name( $group_obj );?></a*

    this works for me,
    maybe there is another way,
    thanks for helping.

    • This reply was modified 2 years, 9 months ago by Vlad.
  • Participant
    Level: Enlightened
    Posts: 33
    Vlad on #42963

    yes, this is a file in my theme single-content.php

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #42966

    Hello Vlad,

    Try the following code:

    
    add_filter( 'the_content', function ( $content ) {
    
    	if ( ! function_exists( 'groups_get_group' ) ) {
    		return $content;
    	}
    
    	global $post;
    
    	$group_id = get_post_meta( $post->ID, '_bcg_group_id', true );
    	$group    = empty( $group_id ) ? '' : groups_get_group( $group_id );
    
    	if ( $group ) {
    		$content = $content . sprintf( 'Associated Group: <a href="%s">%s</a>', bp_get_group_permalink( $group ), bp_get_group_name( $group ) );
    	}
    
    	return $content;
    } );
    
    

    it will append the associated group link with the post content.

    Please let me know if it helps or not.

    Regards
    Ravi

    • This reply was modified 2 years, 9 months ago by Ravi.
  • Participant
    Level: Enlightened
    Posts: 33
    Vlad on #43107

    Thanks Ravi!

    It works.
    Thanks for helping.

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #43112

    Hello Vlad,

    Thank you for the acknowledgment. I am glad to help you.

    Regards
    Ravi

The topic ‘ [Resolved] Link to the group in the text of the post’ is closed to new replies.

This topic is: resolved