Codex

Function Reference/get comments

Contents

Description

Retrieve a list of comments.

Usage

<?php get_comments('array_args'); ?>

Default Usage

 <?php $defaults = array(
    
'status' => ,
    
'orderby' => 'comment_date_gmt',
    
'order' => 'DESC',
    
'number' => 
,
    
'offset' => ,
    
'post_id' => 0); ?> 

Parameters

$status
(string) (optional) Only return comments with this status.
  • 'hold' - unapproved comments
  • 'approve' - approved comments
  • 'spam' - spam comments
Default: None
$orderby
(string) (optional) Set the field used to sort comments.
Default: comment_date_gmt
$order
(string) (optional) How to sort $orderby. Valid values:
  • 'ASC' - Ascending (lowest to highest).
  • 'DESC' - Descending (highest to lowest).
Default: DESC
$number
(integer) (optional) Number of comments to return. Leave blank to return all comments.
Default: unlimited
$offset
(integer) (optional) Offset from latest comment.
Default: 0
$post_id
(integer) (optional) Only return comments for a particular post or page.
Default: None

Returns

(Array) 
List of comments.
    Array indexes
  • comment_author
  • comment_author_email
  • comment_author_url
  • comment_content
  • comment_date

Examples

<?php 
$comments = get_comments('post_id=15');
  foreach($comments as $comm) :
    echo($comm->comment_author);
  endforeach;
?>

Related

See also index of Function Reference and index of Template Tags.