Skip to:
Content
Pages
Categories
Search
Top
Bottom

Integration with PHP for New Topic (bbp 2.1)

  • @hmtodd

    Member

    I just installed 2.1.bleeding to try out bbPress on my site. Totally automatic and smooth as could be. For the record, I’m using the Simple X theme on my blog. Layout needs a little tweaking, but it all worked immediately.

    Most of my site is PHP with the blog secondary. My goal is for the user on a custom PHP page to create a ‘item’ on the base site, and at the same time begin a discussion topic about the ‘item’ on bbPress. They would complete a form with various data that includes a title and comment box. I want to take what they enter and handle part of it on my current site and then create a related new forum topic using the title and comment.

    I suspect this can be done by calling some ‘create topic’ function, but being a novice at this I have no clue how. For the record, my url structure looks like ‘xyz.com/blog/forums’.

    Is this possible? If so, how?

    Thanks for any help,

    Hugh

Viewing 5 replies - 1 through 5 (of 5 total)
  • @hmtodd

    Member

    Hate to answer my own question, but in case anyone wants to try this here is some sample code to start with –

    <html>
    <body>
    This is it.
    <?php
    // include WordPress
    define('WP_USE_THEMES', false);
    require('./blog/wp-load.php');

    // Handle INSERT if data is Posted
    if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == "bbp-new-topic") {
    $new_topic = array(
    'post_parent' => $_POST['bbp_forum_id'], // forum ID
    'post_content' => $_POST['bbp_topic_content'],
    'post_title' => $_POST['bbp_topic_title']
    );
    $topic_meta = array(
    'forum_id' => $new_topic['post_parent']
    );

    $topic_id = bbp_insert_topic($new_topic, $topic_meta);
    echo('<br>Topic ID = '.$topic_id . '<br>');
    } // end INSERT

    // Use Shortcode to show New Topic Form.
    // Could also create your own form.
    echo do_shortcode('[bbp-topic-form]');
    ?>
    Thats it.
    </body></html>

    @zelle7

    Participant

    thank you very much .. I am actually building an api for another weppaplication to communicate with the bbpress forums and I hardly could figure out how to create a new topic in a programmaticaly way out of the documentations

    @avebrahimi

    Participant

    This is awesome, working!

    @avebrahimi

    Participant

    After reading your snippet I used bbp_insert_reply, it’s working very well.

    @piccart

    Participant

    I’ve just made a button on the topic listing page, which send the variable using a GET url:

    <a href="<?php bloginfo( 'url' ); ?>/new-topic/?related_forum_id=<?php bbp_forum_id(); ?>" >New Topic</a>

    then in the template to display the new topic form, you add this:

    <?php // get the var from the new-topic button
    $related_forum_id = $_GET['related_forum_id'];
    // display a warning if there is no info about the id
    if ($related_forum_id=="") {
    	echo "WARNING! Something is wrong here! there is no info about the Related Forum where to append this Topic.<br/>Do not submit the new topic. Please go back and try again.";
    }
    // create a string with the shortcode
    $form_shortcode = '[bbp-topic-form forum_id="'.$related_forum_id.'"]';
    // execute the shortcode to display the form
    echo do_shortcode($form_shortcode); ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Skip to toolbar