$pages->getPath() method

Given an ID, return a path to a page, without loading the actual page

  1. Always returns path in default language, unless a language argument/option is specified.
  2. Path may be different from 'url' as it doesn't include the root URL at the beginning.
  3. In most cases, it's preferable to use $page->path() rather than this method. This method is here just for cases where a path is needed without loading the page.
  4. It's possible for there to be Page::path() hooks, and this method completely bypasses them, which is another reason not to use it unless you know such hooks aren't applicable to you.

Available since version 3.0.6.

Example

// Get the path for page having ID 1234
$path = $pages->getPath(1234);
echo "Path for page 1234 is: $path";

Usage

// basic usage
$string = $pages->getPath($id);

// usage with all arguments
$string = $pages->getPath($id, $options = []);

Arguments

NameType(s)Description
idint, Page

ID of the page you want the path to

options (optional)null, array, Language, int, string

Specify $options array or Language object, id or name. Allowed options include:

  • language (int|string|anguage): To retrieve in non-default language, specify language object, ID or name (default=null)
  • useCache (bool): Allow pulling paths from already loaded pages? (default=true)
  • usePagePaths (bool): Allow pulling paths from PagePaths module, if installed? (default=true)

Return value

string

Path to page or blank on error/not-found.

See Also


$pages methods and properties

API reference based on ProcessWire core version 3.0.236

Latest news

  • ProcessWire Weekly #549
    In the 549th issue of ProcessWire Weekly we’re going to check out the latest core updates, highlight one older yet still very relevant third party module, and more. Read on!
    Weekly.pw / 17 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

“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