In addition to simple posts, you can usually also create pages with a standard WordPress installation. Page-type content can be easily organized hierarchically – a function that is rarely used to its full potential. Complex directories can be created using a page tree, in which any number of pages are organized hierarchically via a parent-child connection. But how do you maintain an overview?
First of all, it is often helpful to be able to use the ID of the parent page for any page. WordPress comes with this functionality – every page basically knows whose child it is. Or to put it more correctly: the ID of the parent page is always also part of the post object.
global $post;
$parent_ID = $post->post_parent;
This snippet can be used to implement a whole host of things.
But what if you are dealing with a multi-level hierarchy?
There are also on-board tools for this: get_post_ancestors
In principle, this function can be used to find all “inheriting” parent pages – i.e. all parent pages.
(…to be continued…)