$page->closest() method

Find the closest parent page matching your selector

This is like $page->parent() but includes the current Page in the possible pages that can be matched, and the $selector argument is required.


$page = $page->closest($selector);


selectorstring, array

Selector string to match.

Return value

Page NullPage

$selector Returns the current Page or closest parent matching the selector. Returns NullPage when no match.

$page methods and properties

API reference based on ProcessWire core version 3.0.234

Latest news

  • ProcessWire Weekly #510
    In the 510th issue of ProcessWire Weekly we'll check out ProcessWire 3.0.236, introduce a new third party module PageFinder Depth from Robin Sallis, and more. Read on!
    Weekly.pw / 17 February 2024
  • Using date range fields in ProcessWire
    This week we'll take a detailed look at the newest addition to the ProFields set of modules: the Date Range Fieldtype and Inputfield.
    Blog / 24 November 2023
  • Subscribe to weekly ProcessWire news

“ProcessWire is like a breath of fresh air. So powerful yet simple to build with and customise, and web editors love it too.” —Margaret Chatwin, Web developer