Thanks to Rahul, I successfully imported my Q&A database to AnsPress. Since I have seen this question a lot of times on AnsPress, I am posting how I did it. Hope it might help someone –
0. Backup everything you are about to change. If you are newbie like me, you never know, when and where silly mistakes are made.
1. Database structure – In my case, I converted my desired Q&A data into simple linear Q&A database, meaning single row contains Question, Answer, Category id, Tag id etc. in respective columns.
Column names are self-explanatory. (“AnsPress_Question_Id” was kept to insert anspress permanent link to the imported question. I had it for my further uses, not needed for most of the cases.)
2. Create a page in wordpress called import.
3. Create a new file called page-import.php inside active theme directory and paste the following code:
a. Update database info (hostname, database name, username, password).
b. Modify code according to your database structure.
c. Check your Category Ids, Tags Ids and User Ids from AnsPress and update the code accordingly. (e.g. while importing I had to add +3 to category id, as this was the difference between my at_qa_dump and wordpress tables)
d. Un-comment following line if you are importing from wordpress root directory (i.e. not by creating page in theme directory)-
4. Increase you PHP execution time : In my case, I changed php execution time to 50,000 (as my database was very large, 30K Q&A). PHP execution time of 5,000 imported approx 2500 Q&A in my first trial. To update it, search and edit following line your server’s php.ini file –
max_execution_time = 5000
5. Open the import page (e.g. http://localhost/your-wordpress-directory-path/import/) and let the query run. Sorry, not a programmer, so my code does not show real-time progress (slight lag is there, depending on number of your imported rows).
Known Issues –
1. In user’s profile page, answer text in answer list appears blank.
2. Importing is slow.
1. I am not at all a programmer. I just did this to make my site live again. All credits to Rahul Aryan, and thanks a lot for his continuous support and help.
2. Rahul and others feel free to make the changes in this procedure, so that it can be easier for others.
I used WP ALL IMPORT too and it works fine for importing separately the tables I had in my original database : “Questions” and “Answers”. One question could receive several answers.
Yet every “Answer” row had a field called “fk__question” which was matching the Question’s ID in my database, so that the system knew which answers to assign to which question.
When trying to import this database into AnsPress I have all the answers imported but none is assigned to a question.
So if I’m not mistaken it boils down to what you said above, create a loop.
That would be something like this :
for each Answer, find‘fk__question’ and the Question it refers too, and import into wp_2_posts as a matching answer ‘Title’ and ‘Content” of the answer(s).
But how do I write that in code please ? I am no programmer either 🙂
Thanks a lot, thanks hugely for four help !!