Issue with inserting questions programmatically

7.82K viewsIssuesAnspress issue
0

Hi,

I tried to insert question programmatically, like you mentioned in your FAQ. In fact, I used almost the same sample code you provided (except that I changed Tag Id and names).

Unfortunately it threw me an error.

Link to my sample gist –

https://gist.github.com/atultiwari/2f0a877e9e63c0c4ed334ecf50189308

 

I have already downloaded the latest one from master branch (and confirmed that manual mode etc are there).

 

Similarly I tried to post answer, it threw me error – “the server responded with a status of 500 (Internal Server Error)”‘

Link to Gist file –

https://gist.github.com/atultiwari/a7c5cfb43324b08125a2cbec6bd15a02

Answer is getting posted with –

$post_id = wp_insert_post($values);

but not with Hook.

I tried to look for where am I making mistake for hours now, but I am unable to figure it out.

 

Edit 1

After the fixed pushed by @Rahul, questions are getting inserted programmatically, as described. However still there are some issues, such as –

  1. Tags are not getting inserted (I tried to find out if it’s with me only or it’s an issue with the script, but I couldn’t), while question and category is inserted correctly
  2. Question metas and activity didn’t get inserted when using sample code provided in FAQ –>I think it’s because of $qameta was never used. I found these working if I use the functions “ap_insert_qameta” and “ap_update_post_activity_meta” on $qameta, however I am not sure if I am using the correct method.
  3. When trying similar method to insert Answer, it didn’t insert post_parent and answer got orphan. While reading the source code for Answer form and related submit function, I observed that here post_parent  is passed under the variable named $question_id , so I tried to pass it like this, but still it failed. var_dump revealed that while passing the value for $question_id it’s storing them in array, first is boolean and in 2nd one it’s strong the parent_post id, which is never used. While if we use the same function on default answer form (when answering the question from GUI), $question_id stores the parent post id. How? I couldn’t understand it.
  4. Even if submitting answer programmatically started working, it will also need some metas and activity update for answer as well to complete the all steps.
  5. I think in complete source section of the FAQ line 15 you forgot to put ; therefore it’s not working at all (out of the box)

Regards,

Atul

Attachments

err1.png
0

Hello Dr Atul,

I will check it again and update our FAQ with full working code.

commented on answer

Ok. I will wait for your update, as whatever I tried couldn’t solve all issues, resulting in waste of time only.

Hi, were you able to check it?

I am checking now.

Ok.. waiting for your update

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