<?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.";
?>