PagesLoader::getByPath() method

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

Please note

  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.
  4. See also the newer/more capable $pages->pathFinder() methods get('/path/') and getPage('/path/').

Usage

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

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

Arguments

NameType(s)Description
pathstring
options (optional)array, bool

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

  • getID (bool): 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)
  • allowUrl (bool): Allow getting page by path OR url? Specify false to find only by path. This option only applies if the site happens to run from a subdirectory. (default=true) 3.0.184+
  • allowPartial (bool): Allow partial paths to match? (default=true) 3.0.184+
  • allowUrlSegments (bool): Allow paths with URL segments to match? When true and page match cannot be found, the closest parent page that allows URL segments will be returned. Found URL segments are populated to a _urlSegments array property on the returned page object. This also cancels the allowPartial setting. (default=false) 3.0.184+

Return value

Page int

See Also


PagesLoader 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

“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