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

Latest news

  • ProcessWire Weekly #558
    In the 558th issue of ProcessWire Weekly we'll check out the blog post that introduces ProcessWire 3.0.244, share some recent ProcessWire highlights, and more. Read on!
    Weekly.pw / 18 January 2025
  • ProcessWire 3.0.244 new main/master version
    ProcessWire 3.0.244 is our newest main/master/stable version. It's been more than a year in the making and is packed with tons of new features, issue fixes, optimizations and more. This post covers all the details.
    Blog / 18 January 2025
  • Subscribe to weekly ProcessWire news

“We chose ProcessWire because of its excellent architecture, modular extensibility and the internal API. The CMS offers the necessary flexibility and performance for such a complex website like superbude.de. ProcessWire offers options that are only available for larger systems, such as Drupal, and allows a much slimmer development process.” —xport communication GmbH