PageTraversal::numChildren()

Return number of children, optionally with conditions

Use this over $page->numChildren property when you want to specify a selector or when you want the result to include only visible children. See the options for the $selector argument.

Usage

// basic usage
$int = $pageTraversal->numChildren(Page $page);

// usage with all arguments
$int = $pageTraversal->numChildren(Page $page, $selector = null, array $options = []);

Arguments

NameType(s)Description
$pagePage
$selector (optional)bool string int array

When not specified, result includes all children without conditions, same as $page->numChildren property. When a string or array, a selector is assumed and quantity will be counted based on selector. When boolean true, number includes only visible children (excludes unpublished, hidden, no-access, etc.) When boolean false, number includes all children without conditions, including unpublished, hidden, no-access, etc. When integer 1 number includes viewable children (as opposed to visible, viewable includes hidden pages + it also includes unpublished pages if user has page-edit permission).

$options (optional)array
  • descendants (bool): Use descendants rather than direct children

Return value

int

Number of children


PageTraversal methods and properties

API reference based on ProcessWire core version 3.0.255