HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Please upgrade here. These earlier versions are no longer being updated and have security issues.

Create Vanilla Forum Discussions Programmatically

edited October 2016 in Vanilla 2.0 - 2.8

I need to create vanilla forum discussions programmatically.

I have a php script which can create "title", "description" and category. Now I need a function to create discussions Programmatically.

Is it possible with Vanilla Forum?

Note 1: It is possible with WordPress using wp_insert_post() function.

Tagged:

Comments

  • Yes it's possible!

    $DiscussionModel = new DiscussionModel();
    $DiscussionModel->SpamCheck = FALSE;
    
    $DiscussionData = array(
        'Name' => $StoryTitle,
        'Body' => $StoryBody,
        'CategoryID' => $CategoryID,
        'Format' => $Format,
        'DateInserted' => Gdn_Format::toDateTime($Timestamp),
        'InsertUserID' => $UserID,
        'UpdateCategoryID' => $CategoryID,
        'DateUpdated' => Gdn_Format::toDateTime($Timestamp),
        'UpdateUserID' => $UserID
    );
    $InsertID = $DiscussionModel->Save($DiscussionData);
    $DiscussionModel->Validation->Results(TRUE);
    
    
    R_Jhgtonight
  • @Caylus said:
    Yes it's possible!

    $DiscussionModel = new DiscussionModel();
    $DiscussionModel->SpamCheck = FALSE;
    
    $DiscussionData = array(
        'Name' => $StoryTitle,
        'Body' => $StoryBody,
        'CategoryID' => $CategoryID,
        'Format' => $Format,
        'DateInserted' => Gdn_Format::toDateTime($Timestamp),
        'InsertUserID' => $UserID,
        'UpdateCategoryID' => $CategoryID,
        'DateUpdated' => Gdn_Format::toDateTime($Timestamp),
        'UpdateUserID' => $UserID
    );
    $InsertID = $DiscussionModel->Save($DiscussionData);
    $DiscussionModel->Validation->Results(TRUE);
    
    

    Thanks for your answer. I need to do this type of lots of thing. Is there any documentation to find something like this?

  • R_JR_J Ex-Fanboy Munich Admin

    There is no specific documentation for that. But take a look at this plugin: https://vanillaforums.org/addon/datagenerator-plugin

    It should be a good guide.

Sign In or Register to comment.