What are various Metas consumed before and after posting any Question or Answer?

4.76K viewsGeneralAnspress features
0

Hi,

As you know, I am planning to start from scratch, which includes adding around 60,000 Q&A programmatically. Long back I wrote a raw script to add Q&A programmatically and posted on Anspress too –

https://anspress.io/questions/question/tutorial-how-to-import-questions-and-answers-to-anspress/

But a lot has changed since then. I wanted to know what are different metas consumed when a question or answer is posted, and more importantly How to update those in a fast way(using hard coding)?

I know you had earlier suggested to some user “ap_save_question”

https://anspress.io/resources/functions/ap_save_question/

which is deprecated now. Then I read about “submit_question_form”

https://anspress.io/resources/methods/ap_form_hooks-submit_question_form/

From here I got the basic idea. But it’s very difficult to reverse trace all the metas used by this function (and sub-functions). Also, there are parts which can Not be there when adding Q&A programmatically (such as redirect to newly posted Question).

 

So I need to make a new function, which will just add new question/answer and its metas.

 

For e.g, I have just striped a part (adding question programmatically) of script which I posted earlier –

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

 

 

Sorry, it seems I was not able to embed codes here, so added screenshot, for better understanding.

In the above e.g., I used wp_set_post_terms for adding category & tags.

Can this be used with current version of Anspress?

So far I can think of following metas, which are being used in posting Q&A –

  1. Category
  2. Tags
  3. Activities
  4. View counts
  5. Timestamp

But, I am not sure how to use these in my script?

Please share your inputs regarding this.

 

Thanks.

Regards,

Atul

Attachments

question.png

Hello Atul,
Please give me an hour to submit a detailed answer with working example.

@Rahul, were you able to make any working example regarding this?

Yeh, still writing the post. Its long so taking time. I will notify you once done.

@Rahul, is the post still under-construction? Can you please forward me any rough draft that you have prepared, as I am kind of stuck on this for some days now. Thanks.

Sorry for delay, about to publish it. There was network issue from few days so I was unable to post.

1

Thank you for the self-explanatory post. I see that you have made some changes in Anspress code itself like “manual mode true” for programmatically adding new question etc. My work is reduced to 40% as you have already modified the anspress. One question though, are the similar changes been done for importing answers, meaning if we can just simply modify the code provided in your FAQ post (adding parentid and post type to answer), will it work? Or that will require some more changes. Thank you again for your post. I am sure even many newcomers will find it useful.

Ok, let me add manual argument for answer form as well. I will push in a minute.

Thank you for reply. I will wait for answer form to get updated. If it’s pushed today then I will test it in the evening and post my results here.

It was pushed same day.

I yes I noticed that and tested, but both question and answer didn’t work for me. I posted that in a separate question (unanswered at present). I did some more work. I am posting it under that question.