FieldtypeComments::find() method

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.248

Latest news

  • ProcessWire Weekly #582
    The 582nd issue of ProcessWire Weekly brings in all the latest news from the ProcessWire community. Modules, sites, and more. Read on!
    Weekly.pw / 5 July 2025
  • New ProcessWire admin redesign
    When you upgrade to ProcessWire 3.0.248 or newer (currently the dev branch), you’ll immediately notice something new and beautiful…
    Blog / 9 May 2025
  • Subscribe to weekly ProcessWire news

“Yesterday I sent the client a short documentation for their ProcessWire-powered website. Today all features already used with no questions. #cmsdoneright—Marc Hinse, Web designer/developer