Skip to:
Content
Pages
Categories
Search
Top
Bottom

Create new forum topic from a WP post?

  • @blooble

    Participant

    Hey, everyone. I am looking for a solution to this and not sure if it exists. My search skills are coming up short so I apologize if it’s out there already.

    I would like to have a link/button on each of my posts in WordPress that would allow the user to generate a new topic in a particular bbPress forum. Essentially, it would auto-fill the title of the topic with the title of the post and quote the contents of the post (perhaps to a certain limit). The user would then be able to add any additional comments before submitting the new topic to the forum.

    Now, of course you are going to ask WHY I want to do this. Essentially, the site I’m building consists of two parts. One, a discussion forum, and two, an rss aggregator that creates a new post for each article brought in from the feed. I would like the user to have the option of bouncing any article/post they think is worthy of discussion to the forum. (I’m not looking to have a discussion on every single post, and I don’t want to use comments under the post, keeping it all to the bbPress forums.)

    I’d appreciate any help that would point me in the right direction. Thanks.

Viewing 12 replies - 1 through 12 (of 12 total)
  • @elhardoum

    Participant

    Hello, here are the steps for you:

    1. Create a ‘new topic’ page at example.com/new-topic/ and add [bbp-topic-form] shortcode as content.
    2. Add this code to your child theme’s functions file:

    add_filter('the_content', function($content) {
    
    	global $post;
    
    	if( 'post' == $post->post_type && is_user_logged_in() ) {
    		$content .= '<p><a href="' . home_url('new-topic/?se_pid=' . $post->ID) . '">Generate a topic</a></p>';
    	}
    
    	return $content;
    
    });
    
    add_action('init', function() {
    
    	$content = null;
    
    	if( isset( $_GET['se_pid'] ) ) {
    		$pid = (int) $_GET['se_pid'];
    		$content = get_post( $pid );
    	}
    
    	$GLOBALS['se_post'] = $content;
    
    });
    
    add_filter('bbp_get_form_topic_title', function( $title ) {
    
    	global $se_post;
    
    	if( $se_post ) {
    		return $se_post->post_title;
    	}
    
    	return $title;
    
    });
    
    add_filter('bbp_get_form_topic_content', function( $body ) {
    
    	global $se_post;
    
    	if( $se_post ) {
    		return $se_post->post_content;
    	}
    
    	return $body;
    
    });

    Test it out, go to your posts and scroll down to the bottom, click the “generate ..” link and see if it worked.

    I am here for any further customization or if you encounter issues with implementing this.

    Regars,
    Samuel

    @blooble

    Participant

    Thank you for your response, Samuel! I will let you know how it goes as soon as I can test it out. Didn’t want to think I was ignoring you.

    @blooble

    Participant

    Samuel! This is great, works better than I had even envisioned. I may have a few questions about a few tweaks down the road, but what I’m trying to accomplish may just be solved by adjusting how my rss data is formatted on import. Thanks again!

    @wasanajones

    Participant

    thank you @elhardoum

    is there a way to only use the post Excerpt for the forum topic content?

    @helennguyen3687

    Participant

    This helps me a lot, thank you, Samuel Elh

    @elhardoum

    Participant

    You’re welcome all. Happy to be able to help ๐Ÿ™‚


    @wasanajones
    You can use get_the_excerpt( $se_post ) or just post_excerpt property of the WP_Post object:

    Edit the last callback from previous code to go as this:

    add_filter('bbp_get_form_topic_content', function( $body ) {
    	global $se_post;
    	if( $se_post ) {
    		return $se_post->post_excerpt;
    	}
    	return $body;
    });

    I did not test this but I am sure it should work.

    Best,
    Samuel

    @anonymized-15184782

    Inactive

    Hi @blooble, you can add a new topic from the editor of default post cliking on “New > Topic”.
    Let me know.

    -Andrea

    @wasanajones

    Participant

    thanks that is great

    @anonymized-15184782

    Inactive

    There’s that ๐Ÿ˜€

    @ytwebdesigns

    Participant

    @elhardoum
    Hi thanks your code works well..

    Only the second part of code you added for returning exerpt isnt working for me.
    I was using the bbpress topics for posts plugin only it is quuite old now and causes conflicts.

    I would like to return in the new topics the post exerpt + a link back to the original post like this [See the full post at: post-title]
    Would appreciate your help.

    (:

    @specstanza

    Participant

    4 years after your reply, I had to loggin to thank you properly @elhardoum.
    Works amazingly for my CPT. Thank you so much!

    @mguillaume

    Participant

    @Ismail
    Still working 7 years later…
    Fabulous ! Gรฉnial ! Merci so much ! ๐Ÿ™‚

Viewing 12 replies - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.
Skip to toolbar