Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
479 views
in Plugins by
I have 10000+ questions and answers in my Excel file. how can I post it at a time using different user id for questions and some fixed user id for answers.
Q2A version: 1.8.8

1 Answer

0 votes
by

Bulk Content Generator will help you.

 

by
any discount? its a little bit high price i think
by
anyone here to give any alternative ?
by
<?php
// Include Q2A core functions
require_once 'qa-include/qa-base.php';
require_once QA_INCLUDE_DIR.'app/posts.php';  // For qa_post_create function

// Open the CSV file
$file = fopen("data.csv", "r");

while (($data = fgetcsv($file, 1000, ",")) !== FALSE) {
    $title = $data[0];  // Question title
    $question_content = $data[1];  // Question content
    $answer_content = $data[2];  // Answer content

    // Anonymous user details
    $anonymous_name = "Visitor";  // Display name for anonymous users
    $anonymous_email = "visitor@example.com";  // Optional email (can be null)
    $anonymous_ip = qa_remote_ip_address();  // Get the visitor's IP address

    // Create the question as an anonymous user
    $question_id = qa_post_create(
        'Q',
        null,  // No user ID (for anonymous user)
        $anonymous_name,  // Name of the visitor
        $anonymous_ip,  // IP address of the visitor
        $title,  // Question title
        $question_content,  // Question content
        '',  // Format (HTML, Markdown, etc. - leave blank for default)
        array(),  // Tags (leave as an empty array if none)
        null,  // Category ID (optional)
        null  // No parent ID for questions
    );

    // Create the answer as an anonymous user
    qa_post_create(
        'A',
        null,  // No user ID (for anonymous user)
        $anonymous_name,  // Name of the visitor
        $anonymous_ip,  // IP address of the visitor
        '',  // No title for answers
        $answer_content,  // Answer content
        '',  // Format (HTML, Markdown, etc.)
        array(),  // Tags (leave as an empty array)
        $question_id,  // Parent ID (the question ID this answer belongs to)
        null  // Category ID (optional)
    );
}

fclose($file);

echo "Import completed successfully.";
?>
...