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

Latest news

  • ProcessWire Weekly #547
    In the 547th issue of ProcessWire Weekly we're going to check out the latest core updates, introduce a couple of new modules, and more. Read on!
    Weekly.pw / 2 November 2024
  • Custom Fields Module
    This week we look at a new ProFields module named Custom Fields. This module provides a way to rapidly build out ProcessWire fields that contain any number of subfields/properties within them.
    Blog / 30 August 2024
  • 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