Search code examples
phpwordpressbuddypressbbpress

Create New topic in Fourms in bbpress WordPress


I want to create new topic using code/programmatically in bbpress WordPress.I searched but didn't find any related code.Can anyone help me by providing any kind of help related.Thanks


Solution

  • Try these functions :

     bbp_insert_topic(), bbp_insert_forum(), and bbp_stick_topic()
    

    For details you can try like this :

    $topic_data = apply_filters( 'bbp_new_topic_pre_insert', array(
            'post_author'    => $topic_author,
            'post_title'     => $topic_title,
            'post_content'   => $topic_content,
            'post_status'    => $topic_status,
            'post_parent'    => $forum_id,
            'post_type'      => bbp_get_topic_post_type(),
            'tax_input'      => $terms,
            'comment_status' => 'closed'
        ) );
    
        // Insert topic
        $topic_id = wp_insert_post( $topic_data );
    

    You can also found this code in plugin/bbpress/includes/funcion.php page.Hope this can help you