$page->numDescendants() method

Return number of descendants (children, grandchildren, great-grandchildren, …), optionally with conditions

Use this over the $page->numDescendants property when you want to specify a selector or apply some other filter to the result (see options for $selector argument). If you want to include only visible descendants specify a selector (string or array) or boolean true for the $selector argument, if you don’t need a selector.

If you want to find descendant pages (rather than count), use the Page::find() method.

Example

// Find how many descendants were modified in the last week
$qty = $page->numDescendants("modified>='-1 WEEK'");

Usage

// basic usage
$int = $page->numDescendants();

// usage with all arguments
$int = $page->numDescendants($selector = null);

Arguments

NameType(s)Description
selector (optional)

Return value

int

Number of descendants

See Also


$page methods and properties

API reference based on ProcessWire core version 3.0.137

Twitter updates

  • ProcessWire 3.0.144 and 3.0.145 add improved field template context override settings and include a new Inputfields API, along with numerous other issue fixes, optimizations and improvements to the core. More
    8 November 2019
  • ProcessWire 3.0.144 core updates: Upgraded overrides section in the field editor, a new Inputfields JS API, and more— More
    1 November 2019
  • ProcessWire 3.0.143 core updates — 26 commits and 18 resolved issue reports, plus some other useful improvements and additions. More here: More
    25 October 2019

Latest news

  • ProcessWire Weekly #288
    In the 288th issue of ProcessWire Weekly we'll cover the latest core updates, introduce WireMailSendGrid, host a new weekly poll, and showcase a new site of the week. Read on!
    Weekly.pw / 16 November 2019
  • ProcessWire 3.0.145 core updates
    ProcessWire 3.0.144 and 3.0.145 add improved field template context override settings and include a new Inputfields API, along with numerous other issue fixes, optimizations and improvements to the core.
    Blog / 8 November 2019
  • Subscribe to weekly ProcessWire news

“Yesterday I sent the client a short documentation for their ProcessWire-powered website. Today all features already used with no questions. #cmsdoneright—Marc Hinse, Web designer/developer