PageFinder::find() method

Return all pages matching the given selector.

Usage

// basic usage
$array = $pageFinder->find($selectors);

// usage with all arguments
$array = $pageFinder->find($selectors, array $options = []);

Arguments

NameType(s)Description
selectorsSelectors, string, array

Selectors object, selector string or selector array

options (optional)array
  • findOne (bool): Specify that you only want to find 1 page and don't need info for pagination (default=false).
  • findHidden (bool): Specify that it's okay for hidden pages to be included in the results (default=false).
  • findUnpublished (bool): Specify that it's okay for hidden AND unpublished pages to be included in the results (default=false).
  • findTrash (bool): Specify that it's okay for hidden AND unpublished AND trashed pages to be included in the results (default=false).
  • findAll (bool): Specify that no page should be excluded - results can include unpublished, trash, system, no-access pages, etc. (default=false)
  • getTotal (bool|null): Whether the total quantity of matches should be determined and accessible from getTotal() method call.
    • null: determine automatically (default is disabled when limit=1, enabled in all other cases).
    • true: always calculate total.
    • false: never calculate total.
  • getTotalType (string): Method to use to get total, specify 'count' or 'calc' (default='calc').
  • returnQuery (bool): When true, only the DatabaseQuery object is returned by find(), for internal use. (default=false)
  • loadPages (bool): This is an optimization used by the Pages::find() method, but we observe it here as we may be able to apply some additional optimizations in certain cases. For instance, if loadPages=false, then we can skip retrieval of IDs and omit sort fields. (default=true)
  • stopBeforeID (int): Stop loading pages once a page matching this ID is found. Page having this ID will be excluded as well (default=0).
  • startAfterID (int): Start loading pages once a page matching this ID is found. Page having this ID will be excluded as well (default=0).
  • reverseSort (bool): Reverse whatever sort is specified.
  • returnVerbose (bool): When true, this function returns array of arrays containing page ID, parent ID, template ID and score. When false, returns only an array of page IDs. True is required by most usage from Pages class. False is only for specific cases.
  • returnParentIDs (bool): Return parent IDs only? (default=false, requires that 'returnVerbose' option is false).
  • returnTemplateIDs (bool): Return [pageID => templateID] array? [3.0.152+ only] (default=false, cannot be combined with other 'return*' options).
  • returnAllCols (bool): Return [pageID => [ all columns ]] array? [3.0.153+ only] (default=false, cannot be combined with other 'return*' options).
  • allowCustom (bool): Whether or not to allow _custom='selector string' type values (default=false).
  • useSortsAfter (bool): When true, PageFinder may ask caller to perform sort manually in some cases (default=false).

Return value

array DatabaseQuerySelect

Exceptions

Method can throw exceptions on error:

  • PageFinderException


Hooking PageFinder::find(…)

You can add your own hook events that are executed either before or after the PageFinder::find(…) method is executed. Examples of both are included below. A good place for hook code such as this is in your /site/ready.php file.

Hooking before

The 'before' hooks are called immediately before each PageFinder::find(…) method call is executed. This type of hook is especially useful for modifying arguments before they are sent to the method.

$this->addHookBefore('PageFinder::find', function(HookEvent $event) {
  // Get the object the event occurred on, if needed
  $PageFinder = $event->object;

  // Get values of arguments sent to hook (and optionally modify them)
  $selectors = $event->arguments(0);
  $options = $event->arguments(1);

  /* Your code here, perhaps modifying arguments */

  // Populate back arguments (if you have modified them)
  $event->arguments(0, $selectors);
  $event->arguments(1, $options);
});

Hooking after

The 'after' hooks are called immediately after each PageFinder::find(…) method call is executed. This type of hook is especially useful for modifying the value that was returned by the method call.

$this->addHookAfter('PageFinder::find', function(HookEvent $event) {
  // Get the object the event occurred on, if needed
  $PageFinder = $event->object;

  // An 'after' hook can retrieve and/or modify the return value
  $return = $event->return;

  // Get values of arguments sent to hook (if needed)
  $selectors = $event->arguments(0);
  $options = $event->arguments(1);

  /* Your code here, perhaps modifying the return value */

  // Populate back return value, if you have modified it
  $event->return = $return;
});

PageFinder methods and properties

API reference based on ProcessWire core version 3.0.236

Latest news

  • ProcessWire Weekly #550
    In the 550th issue of ProcessWire Weekly we're going to check out the latest core updates, introduce a new third party module called PagefileMetadata, and more. Read on!
    Weekly.pw / 23 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

I just love the easy and intuitive ProcessWire API. ProcessWire rocks!” —Jens Martsch, Web developer