get_page_uri( WP_Post|object|int $page ): string|false

Builds the URI path for a page.

Description

Sub pages will be in the "directory" under the parent page post name.

Parameters

$pageWP_Post|object|intoptional
Page ID or WP_Post object. Default is global $post.

Return

string|false Page URI, false on error.

More Information

If the page has parents, those are prepended to the URI to provide a full path. For example, a third level page might return a URI like this:

top-level-page/sub-page/current-page

This function will return a “slug” style URI regardless of whether “pretty” Permalinks are configured.

Source

 * @return string[] Array of post names keyed by ID and arranged by hierarchy. Children immediately follow their parents.
 */
function get_page_hierarchy( &$pages, $page_id = 0 ) {
	if ( empty( $pages ) ) {
		return array();
	}

	$children = array();
	foreach ( (array) $pages as $p ) {
		$parent_id                = (int) $p->post_parent;
		$children[ $parent_id ][] = $p;
	}

	$result = array();
	_page_traverse_name( $page_id, $children, $result );

	return $result;
}

/**
 * Traverses and return all the nested children post names of a root page.
 *
 * $children contains parent-children relations
 *
 * @since 2.9.0
 * @access private
 *
 * @see _page_traverse_name()

Changelog

VersionDescription
4.6.0The $page parameter was made optional.
1.5.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.