Multiple Comment Forms in a single page [closed]

You can pass the number argument to get_comments() to retrieve only a specific number of comments. They will, by standard, be sorted descending, so you get the latest comments first.

As WordPress automatically seperates comments for each post, you will not have to worry about mixing comments up. This seems to be the easiest way for me.

Multiple comment forms per page -> Passing Post ID

If you need multiple comment forms on one page, you can use several get_comments(), but you have to pass the post IDs for the comments you want to show.

Example:

$postID = 4;
$number_of_posts = 6;

$args = array(
    'number' => $number_of_posts,
    'post_id' => $postID
);

$your_comments = get_comments($args);

Make it dynamic -> Extract IDs from post_meta and loop over them

Post IDs are saved comma-seperated in a field called commentIDs, code would be placed in a single.php for example.

// get IDs for current post
$cmmntIDs = get_post_meta($post->ID, 'commentIDs', true);
$theIDs = explode(',', $cmmntIDs);

// get comments for each ID you defined
foreach($theIDs as $theID) {
    $args = array(
        'number' => $number_of_posts,
        'post_id' => $theID
    );
    $comments = get_comments($args);

    // basic output from the Codex Page on get_comments()
    foreach($comments as $comment) {
        echo($comment->comment_author);
    }
}  

Leave a Comment