comments - Adding Parameters to get_comment

admin2025-01-07  3

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?

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?

Share Improve this question edited May 10, 2014 at 13:56 Pieter Goosen 55.4k23 gold badges115 silver badges209 bronze badges asked May 10, 2014 at 12:28 EnginEngin 12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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);
}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736261006a707.html

最新回复(0)