$pages->getByPath() method

Get a page by its path, similar to $pages->get('/path/to/page/') but with more options

  1. There are no exclusions for page status or access. If needed, you should validate access on any page returned from this method.
  2. In a multi-language environment, you must specify the $useLanguages option to be true, if you want a result for a $path that is (or might be) a multi-language path. Otherwise, multi-language paths will make this method return a NullPage (or 0 if getID option is true).
  3. Partial paths may also match, so long as the partial path is completely unique in the site. If you don't want that behavior, double check the path of the returned page.

Available since version 3.0.6.

Example

// Get a page by path 
$p = $pages->getByPath('/skyscrapers/atlanta/191-peachtree/');

// Now validate that the page we retrieved is valid
if($p->id && $p->viewable()) {
  // Page is valid to display
}

// Get a page by path with options
$p = $pages->getByPath('/products/widget/', [
  'useLanguages' => true,
  'useHistory' => true
]);

Usage

// basic usage
$page = $pages->getByPath(string $path);

// usage with all arguments
$page = $pages->getByPath(string $path, $options = []);

Arguments

NameType(s)Description
pathstring

Path of page you want to retrieve.

options (optional)array, bool

array of options (below), or specify boolean for $useLanguages option only.

  • getID (int): Specify true to just return the page ID (default=false).
  • useLanguages (bool): Specify true to allow retrieval by language-specific paths (default=false).
  • useHistory (bool): Allow use of previous paths used by the page, if PagePathHistory module is installed (default=false).

Return value

Page int


$pages 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

“We were really happy to build our new portfolio website on ProcessWire! We wanted something that gave us plenty of control on the back-end, without any bloat on the front end - just a nice, easy to access API for all our content that left us free to design and build however we liked.” —Castus, web design agency in Sheffield, UK