FieldtypeComments::find()

Given a field and a selector, find all comments matching the selector

  • If you don’t specify a “limit=n”, it will default to a limit of 10.
  • If you don’t specify a sort, it will default to “sort=-created”.
  • Arguments may be optionally reversed (for backwards compatibility).

Unlike $pages->find(), pagination of comments is not automatically tied to $input->pageNum(). As a result, if you paginate, you should specify both “start=n” and “limit=n” in your selector:

Please also note that this function returns comments without taking anything about the page they live on into account. As a result, it can return comments from unpublished or non-viewable pages. If you need this, check the returned results:

Examples

$limit = 20;
$start = ($input->pageNum() - 1) * $limit;
$comments = $field->type->find("text%=something, start=$start, limit=$limit"); 
$comments = $field->type->find('text%=something'); 
foreach($comments as $comment) {
  $p = $comment->getPage();
  if(!$p->viewable()) $comments->remove($comment);
}

Usage

// basic usage
$items = $fieldtypeComments->find($selectorString);

// usage with all arguments
$items = $fieldtypeComments->find($selectorString, $field = null, array $options = []);

Arguments

NameType(s)Description
$selectorStringstring null

Selector string with query

$field (optional)
$options (optional)array
  • count (bool): Return a total count rather than a CommentArray? Default:false

Return value

CommentArray int

Exceptions

Method can throw exceptions on error:

  • WireException


FieldtypeComments methods and properties

API reference based on ProcessWire core version 3.0.251