What would the best way to import more than 30,000 questions and answers?

6.59K viewsGeneral
1

Hi,

I want to import a huge database of around 30,000 questions and answers.

I have been trying with following code

https://gist.github.com/rahularyan/7b85c9678ddef2c21208

But, it’s causing meta problems (like even after providing user-id activity log says Anonymous answered…, Question/Answers count and reputation points are not updated).

Also I have read your answer on the question Importing from Django

I tried with merging the two, but even that produces some bugs (e.g. questions/answers count, reputation points etc, activity line).

Also the biggest problem I am facing right now, is to import such a large database. It appears to be taking forever to import 30,000 questions, the actual number of queries to be run would be a lot higher, I think (first, 30k questions, then 30k answers, and their meta-entries) .  I have even increased my localhost timeout.

Can you please suggest me –

1. How should I modify this code or what would be the correct code to import all questions and answers from a linear database (questions and answers are in the same row)?

2. What can be done to increase import speed?

Is this q2a from where you are importing ?

No. It’s not q2a. it’s my custom Q&A database created for multiple choice quiz.
and i have customized it for WordPress-Anspress by having columns such as Question_Title(Post_Title), Question_Content(Post_Content), Answer_Content(Post_Content).

When you used to work on q2a themes, I used a similar code to import Q&A to q2a from this database. But back then, it used have approx 5k questions and answers, even then it took me whole day to import (and some days to understand what are other meta I have to include in my custom script). So I am guessing this time it would take days if I blindly do hit and try.

0

You can initiate you code after WP init hook and everything will as usual.

Create a page in wordpress called import, and then create a new file called page-import.php inside active theme dir and paste your code without:

require('wp-blog-header.php');

and just visit that page and import will be started.

Thanks. I have finally imported my Q&A. I also found 2 things –
1. I was actually using the mentioned code in wp root folder as it is posted above, including “require(‘wp-blog-header.php’);”. The page-import,php method does the very same thing. Meta issues were not caused by my code from wp-root.
2. Meta issues were occurring because anspress meta code uses currently logged in user only, while I was providing user id in my code itself. So both were conflicting.

There were some minor issues in this importing process, but I am OK with that. Although about a few major issues, I will have to post separate questions.

Oops… I came to know about this function little late.. 🙁 It took me whole night to import all Q&A to local wp under single user name only. and earlier this morning I have also migrated the same to my live site too. I don’t see any necessity to rewrite the code and again spend a night for import…इतनी ज्यादा programming की तो लोग मेरे नाम के आगे का Dr. हटा के Er. कर देंगे. thanks anyways.

HAHHAH 🙂 does happen

You are viewing 1 out of 3 answers, click here to view all answers.