0

I have a code like this:

<?php $comments = get_comments( 'post_id=' . $post->ID ); echo get_comment_author($comments[0]->comment_ID); ?>
<br />
<?php $comments = get_comments( 'post_id=' . $post->ID ); echo get_comment_date('d F H:i', $comments[0]->comment_ID); ?>

and i want to include 'approve' - approved comments into this code.

I am familiar with this code:

<?php $defaults = array(
    'ID' => '',
    'number' => '1',
    'order' => 'DESC',
    'status' => 'approved',
); ?>

But I am unable to integrate both codes.

My point is: show posts last commenter name and comment date d F H:i together. Any suggestions?

1 Answer 1

0

My point is: show posts last commenter name and comment date d F H:i together. Any suggestions?

I think what you want is:

$defaults = array(
    'post_id' => $post->ID,
    'number' => '1',
    'orderby' => 'comment_date_gmt ', // default value; not really necessary
    'order' => 'DESC',
    'status' => 'approved',
);

You shouldn't need to run get_comments() twice.

$defaults = array(
    'post_id' => 120,
    'number' => '1',
    'orderby' => 'comment_date_gmt ', // default value; not really necessary
    'order' => 'DESC',
    'status' => 'approved',
);
$comments = get_comments($defaults);
if (!empty($comments[0])) {
  $comments = $comments[0];
  comment_author($comments->comment_ID);
  comment_date('d F H:i', $comments->comment_ID);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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