Get WordPress Single Post Comments in loop.

I was working on a WordPress site that seemed to not want to pull in the single post comments, so I had to hard code it in somehow.

Did a little search and came across this: http://wordpress.stackexchange.com/questions/3141/getting-post-comments-for-post-id-using-wp-query-and-a-custom-loop – See Talha’s comment at the bottom. Thanks dude 🙂

His solution:

$comments = get_comments('post_id='.$post->ID);
foreach($comments as $comment) :
print_r
($comment);
endforeach
;



My edits for styling:

<div class="currentComments">
<h3 id="reply-title">Comments</h3>
<?php
$comments = get_comments('post_id='.$post->ID);
foreach($comments as $comment) :
echo '<div class="singleComment"><h4>';
print_r($comment->comment_author);
echo "&nbsp;on&nbsp;";
print_r($comment->comment_date);
echo "</h4>";
print_r($comment->comment_content);
echo "<br />";
echo '</div>';
//print_r($comment);
endforeach;
?>
</div>



Works like a charm, just style each comment as needed.

2 thoughts on “Get WordPress Single Post Comments in loop.

Leave a Reply

Your email address will not be published. Required fields are marked *