Skip to:
Content
Pages
Categories
Search
Top
Bottom

Create a new forum on each new post?


  • slugs
    Participant

    @slugs

    Hi bbpress guys,

    I would like to create a new forum on each post. Similar to the discussion boards that use to be on imdb.

    I guess what im looking for is similar to bbpress-post-topics/

    So, if you imagine. I post a movie review about “james bond”. I would like people on that post to be able to create new topics in that forum. This forum would be present on that post/page and only contain only topics relating to that post/page.

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

  • hellojesse
    Participant

    @egyptimhotep

    I can help, you need to use hooks. If post is created, create a forum like post id of movie review. Then call shortcode with dynamic id of ppost form which is same as pos id of review.

    If you need code, contact me.


    slugs
    Participant

    @slugs

    Hi @egyptimhotep,

    Yes please, could you provide code?

    I wasn’t sure how to contact you on slack? There are a eight people with the handle @Jesse.

    Thanks,

    Slugs


    hellojesse
    Participant

    @egyptimhotep

    I do not use slack, BTW, I love https://matrix.org/ messenger.

    I will do it for you and notify you here in this topic.

    I will do simple theme to demonstrate what you need from scratch with this functionality, is it ok for you?


    slugs
    Participant

    @slugs

    Yes, thank you a simple theme to demonstrate will be fine. I’m not too sure how to use hooks and I get very confused with how to use short codes and php together.


    hellojesse
    Participant

    @egyptimhotep

    Do not worry, I will explain all details.


    hellojesse
    Participant

    @egyptimhotep

    Home Page
    https://ibb.co/8Mpg1hg

    Dedicated forum for your review
    https://ibb.co/JnBwV9T


    hellojesse
    Participant

    @egyptimhotep

    Here is your theme, if you have any question, just ask me.

    http://up-4ever.org/d/Ej72


    slugs
    Participant

    @slugs

    That works great! Thank you so much.

    How do I add the post content to the first post of the new topic? I can’t work out how to target the first post with add_action().

    How do I append the post post title to the forum id? It looks like this (Forum: 67) it might be better if it was post-title-67 e.g starwars-67

    I would like the first forum topic created to be displayed on the post page. I currently achieve this by:

    Add new block

    [/] shortcode

    Add the bbpress shortcode

    [bbp-single-topic id=40]

    The id is found when edititing the topic in the address bar https://site/wp-admin/post.php?post=40&action=edit

    Is there a way of automating this task?


    hellojesse
    Participant

    @egyptimhotep

    How do I append the post post title to the forum id?

    Change this <h2>Forum: <?php echo get_the_ID(); ?></h2>
    to this: <h2>Forum: <?php echo basename(get_permalink()); ?></h2>


    hellojesse
    Participant

    @egyptimhotep

    How do I add the post content to the first post of the new topic?

    Under this action:
    add_action('transition_post_status', 'send_new_post', 10, 3);

    Replace with updated function:

    // Listen for publishing of a new post
    function send_new_post($new_status, $old_status, $post) {
      if('publish' === $new_status && 'publish' !== $old_status && $post->post_type === 'post') {
    	$my_post = array(
    	  'post_title' => $post->ID,
    	);
    	 
    	$forum_id = bbp_insert_forum($my_post);
    
    	$my_topic = array(
    		'post_title' => $post->post_title,
    		'post_content' => $post->post_content,
    		'post_parent' => $forum_id
    	);
    
    	bbp_insert_topic($my_topic);
      }
    }

    hellojesse
    Participant

    @egyptimhotep

    I would like the first forum topic created to be displayed on the post page.

    You need to add another line of code to action function. We need to save topic id to post meta.

    whole function.php

    // Add the hook action
    add_action('transition_post_status', 'send_new_post', 10, 3);
    
    // Listen for publishing of a new post
    function send_new_post($new_status, $old_status, $post) {
      if('publish' === $new_status && 'publish' !== $old_status && $post->post_type === 'post') {
    	
    	$my_post = array(
    	  'post_title' => $post->ID,
    	);
    	 
    	$forum_id = bbp_insert_forum($my_post);
    
    	$my_topic = array(
    		'post_title' => $post->post_title,
    		'post_content' => $post->post_content,
    		'post_parent' => $forum_id
    	);
    
    	$topic_id = bbp_insert_topic($my_topic);
    
    	update_post_meta( $post->ID, 'forum_first_topic', $topic_id );
    
      }
    }

    In single.php we can call your shortcode for showing topic by id because whe have post meta.

    Paste this into loop:

    $topic_id = get_post_meta( get_the_ID(), 'forum_first_topic', true );
    echo do_shortcode(' [bbp-single-topic id='.$topic_id.']');

    Whole single php loop:

    <?php if ( have_posts() ) : ?>
    	<?php while ( have_posts() ) : the_post(); ?>    
    	
    		<div class="article">
    			<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>			
    			<?php the_content(); ?>	
    			<h2>Forum: <?php echo basename(get_permalink()); ?></h2>
    			<?php 
    				$post = get_post(get_the_ID());
    				$mypost = get_page_by_title(get_the_ID(),OBJECT,'forum');
    				$topic_id = get_post_meta( get_the_ID(), 'forum_first_topic', true );
    				
    				echo do_shortcode(' [bbp-single-topic id='.$topic_id.']');
    				echo do_shortcode( '[bbp-single-forum id='.$mypost->ID.']' ); ?>
    		</div>
    
    	<?php endwhile; ?>
    <?php endif; ?>

    hellojesse
    Participant

    @egyptimhotep

    It should be easy to understand code and should work as you describe above.

    Do not hesitate to contact me.

    Here are my screenshots:

    Home Page:
    https://ibb.co/8m1225X

    Single Page:
    https://ibb.co/KhCDFtx


    slugs
    Participant

    @slugs

    Wow, amazing it does everything I want. Can’t thank you enough.


    hellojesse
    Participant

    @egyptimhotep

    You welcome. Anytime.

    Would you come to visit my website when is ready, maybe next year? Dedicated to help wp users.


    slugs
    Participant

    @slugs

    Yes, that sounds like a great site idea. I think the web is about 30% wordpress?


    hellojesse
    Participant

    @egyptimhotep

    Dear @slugs,

    I am WordPress evangelist, and we want to cover as much as possible about WP.

    Main features I want to have:

    1. Activity page, like on facebook
    2. Chat
    3. Messenger for users, want push-ups
    4. Project Manager to manage any WP project.

    I will contact you if the site is ready.

    Thank you very much.


    raja123a
    Participant

    @raja123a

    @egyptimhotep
    Forum title remains numeric

    Below is the code in single.php

    <?php if ( have_posts() ) : ?>
    	<?php while ( have_posts() ) : the_post(); ?>    
    	
    		<div class="article">
    			<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>			
    			<?php the_content(); ?>	
    			<h2>Forum: <?php echo basename(get_permalink()); ?></h2>
    			<?php 
    			$post = get_post(get_the_ID());
    			$mypost = get_page_by_title(get_the_ID(),OBJECT,'forum');
    			echo do_shortcode( '[bbp-single-forum id='.$mypost->ID.']' ); ?>
    		</div>
    
    	<?php endwhile; ?>
    <?php endif; ?>

    It would be great if you could help me find, where i made a mistake 🙂

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