WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using Wordpress to create a Q&A website.

The question is returned by the_content.

If I store the answers as post meta field array:

      [1] => 'first answer',
      [2] => 'second answer',
      [3] => 'third answer',

How can I create separte comments for each item (comments for question, then comments for first answer, then comments for second answer....)? Noramlly, I use <?php comments_template( '', true ); ?> which creates comments relative to the_content. If I reuse it, it will display a new comment for all the items. comments_template doesnt have a pramater to identify a list of comments against other lists.

share|improve this question
A better way might be to store the responses as custom posts (using, say, a response custom post type). Then you could use WordPress's comment system to create comments on each response. – Pat J Jun 20 '13 at 19:13
@PatJ. First thank you. I see that is a good idea to consider each response as a CPT post. I have already used CPTs but there is a detail I want you please to clarify to me. How can I link between the CPT posts so that many responses belong to one question. Maybe using a custom field that will be set to the same value for question and its responses? a better approach? – whiteletters in blankpapers Jun 20 '13 at 19:36
You could use something like update_post_meta( $response_id, 'question_id', $question_id ); to tie the responses to the questions. – Pat J Jun 20 '13 at 19:39
You can store QuestionPostID as custom field or "hack" a little bit and set it as post_parent of answer post ;) (You should look out with the second solution - it looks nice, but I guess it may produce troubles with some plugins.) – Krzysiek Dróżdż Jun 20 '13 at 19:41
@PatJ Thank you very much . Could you please post this as answer. – whiteletters in blankpapers Jun 20 '13 at 19:45
up vote 2 down vote accepted

(adding answer from comments above)

Set up your Responses as a Custom Post Type. Then you can use WordPress's native comment system for, well, comments on the Responses.

To tie the Responses to the Questions, you can simply use something like update_post_meta( $response_id, 'question_id', $question_id );. See update_post_meta() for details.

share|improve this answer

I wouldn't use custom fields to store answers. It will be very limited solution (no publish date, no author, and so on).

Much better solution is to store answers as comments (and use nested/threaded comments) for question post or as Custom Posts (using Custom Post Type) - the second solution would be even nicer and cleaner.

share|improve this answer
You are convincing me. I totally agree with this nice approach. But I think I will use CPT since you are two people to talk me about it (You and PATJ) . Thank you for your time Krzysiek Dróżdż. – whiteletters in blankpapers Jun 20 '13 at 19:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.