get_comments( string|array $args = '' )

Retrieve a list of comments.

Description Description

The comment list can be for the blog as a whole or for an individual post.

Parameters Parameters


(string|array) (Optional) Array or string of arguments. See WP_Comment_Query::__construct() for information on accepted arguments.

Default value: ''

Top ↑

Return Return

(int|array) List of comments or number of found comments if $count argument is true.

Top ↑

Source Source

File: wp-includes/comment.php

function get_comments( $args = '' ) {
	$query = new WP_Comment_Query;
	return $query->query( $args );

Top ↑

Changelog Changelog

Version Description
2.7.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note content
    Contributed by Codex

    Show last 5 unapproved comments

    $args = array(
    	'status'  => 'hold',
    	'number'  => '5',
    	'post_id' => 1, // use post_id, not post_ID
    $comments = get_comments( $args );
    foreach ( $comments as $comment ) :
    	echo $comment->comment_author . '<br />' . $comment->comment_content;

You must log in before being able to contribute a note or feedback.