Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
477 views
in Q2A Core by

Is it possible to use qa_post_create with custom id?

I do know it will return the id, but Can I choose the id?

qa_post_create($type, $parentpostid, $title, $content, $format, $categoryid, $tags, $userid)

by
Out of curiosity, why would you even want to do that in the first place? What would be the benefits?
by
I have an excel file with list of questions, with its answers I'd like to import it. The questions with their answers share the same ids
by
That's not how the Q2A database works. Please take an actual look at how the table qa_posts is defined. Answers are associated with question via the field "parent_id," NOT by sharing the same value in the field "post_id."
I believe questions about bulk-importing data pop up with some frequency here. Please do some research.
by
Yeah sure, first I'll import questions, then answers after getting the ids. Correct?
by
Yes. Basically you'd import a question, then import the answers to that question using the post ID returned by the question import as the parent ID for the answers.

1 Answer

0 votes
by
The post ID is managed by the database backend. In theory you could modify the code to allow providing the ID yourself, but that would AFAICS require some serious patching of core code. You'd also have the additional burden of handling conflicts (what happens if the chosen ID is already present in the database?) and perhaps even input sanitization, depending on who you want to allow specifying the ID.

I would strongly discourage doing this.
...