Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
2  
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 and blankspaces Jun 20 '13 at 19:36
2  
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
1  
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 and blankspaces Jun 20 '13 at 19:45
add comment

2 Answers

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
add comment

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 and blankspaces Jun 20 '13 at 19:46
add comment

Your Answer

 
discard

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.