Skip navigation


6 comment.module comment_get_recent($number = 10)
7 comment.module comment_get_recent($number = 10)

Find the most recent comments that are available to the current user.


integer $number: (optional) The maximum number of comments to find. Defaults to 10.

Return value

An array of comment objects or an empty array if there are no recent comments visible to the current user.

1 call to comment_get_recent()


drupal/modules/comment/comment.module, line 502
Enables users to comment on published content.


function comment_get_recent($number = 10) {
  $query = db_select('comment', 'c');
  $query->innerJoin('node', 'n', 'n.nid = c.nid');
  $comments = $query
    ->condition('c.status', COMMENT_PUBLISHED)
    ->condition('n.status', NODE_PUBLISHED)
    ->orderBy('c.created', 'DESC')
    // Additionally order by cid to ensure that comments with the same timestamp
    // are returned in the exact order posted.
    ->orderBy('c.cid', 'DESC')
    ->range(0, $number)

  return $comments ? $comments : array();