tools/wordpress-comment-query-generator
WordPress Comment Query Generator
Build a WP_Comment_Query call with the status and type strings WordPress actually recognises — filter by post, author or parent, count matches, or walk a threaded list.
snippet.php
$args = array(
'status' => 'approve',
'type' => 'comment',
'orderby' => 'comment_date_gmt',
'order' => 'DESC',
'number' => 10,
);
$comment_query = new WP_Comment_Query();
$comments = $comment_query->query( $args );
if ( ! empty( $comments ) ) {
echo '<ul>';
foreach ( $comments as $comment ) {
printf(
'<li><strong>%s</strong>: %s</li>',
esc_html( $comment->comment_author ),
esc_html( get_comment_text( $comment ) )
);
}
echo '</ul>';
} else {
printf( '<p>%s</p>', esc_html__( 'No comments found.', 'text-domain' ) );
}