get_comments

Retrieve a list of comments.

Description

(int|array) get_comments( (string) $args = '' ); 

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

Returns (int|array)

List of comments or number of found comments if `$count` argument is true.

Parameters (1)

0. $args — Optional. (string) => ''
Array or string of arguments. See WP_Comment_Query::parse_query() for information on accepted arguments. Default empty.

Usage

  1. if ( !function_exists( 'get_comments' ) ) { 
  2. require_once ABSPATH . WPINC . '/comment.php'; 
  3.  
  4. // Optional. Array or string of arguments. See WP_Comment_Query::parse_query() 
  5. // for information on accepted arguments. Default empty. 
  6. $args = ''; 
  7.  
  8. // NOTICE! Understand what this does before running. 
  9. $result = get_comments($args); 
  10.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/comment.php  
  1. function get_comments( $args = '' ) { 
  2. $query = new WP_Comment_Query; 
  3. return $query->query( $args );