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 #579
    The 579th issue of ProcessWire Weekly brings in all the latest news from the ProcessWire community. Modules, sites, and more. Read on!
    Weekly.pw / 14 June 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

“To Drupal, or to ProcessWire? The million dollar choice. We decided to make an early switch to PW. And in retrospect, ProcessWire was probably the best decision we made. Thanks are due to ProcessWire and the amazing system and set of modules that are in place.” —Unni Krishnan, Founder of PigtailPundits