$forum_id, 'post_type' => 'topic', ] ); $add = 2; $order = count( $parent_item ); $order = $order + $add; // Create topic object $topic_data = apply_filters( 'bbp_new_topic_pre_insert', [ 'post_author' => $topic_author, 'post_title' => $bbp_topic_title, 'post_parent' => $forum_id, 'post_content' => '', 'post_type' => bbp_get_topic_post_type(), 'post_status' => 'publish', 'menu_order' => $order, ] ); $topic_id = wp_insert_post( $topic_data, true ); if ( is_wp_error( $topic_id ) ) { wp_send_json_error( 'Failed to create the topic.' ); } do_action( 'bbp_new_topic', $topic_id, $forum_id, '', $topic_author ); wp_send_json_success( 'Topic created successfully.' ); }