How does wordpress calculate the page depth?

When using functions such as wp_list_pages(), WordPress gives you the depth option. How is it calculated?

Is it stored somewhere in the DB? (I couldn’t find it).

Or is it calculated in a loop checking post parents?

What’s strange is that wp_list_pages() offer the parameter depth but that function is based of get_pages() which doesn’t have that same option available.

1 Answer
1

Ok, lets break it down, all the links are going to be to the source code.

wp_list_pages() only uses get_pages() to (sic!) get pages, walk_page_tree() does the hierarchical structuring inside it. The further course of the process goes Walker_Page – and the generic Walker of course -, unless a custom walker is used. Inside walk_page_tree() you will see, the walkers walk method is called, which subsequently calls the display_element method. Mainly in the display_element, but also in the walk, method you find the handling of the depth.

To make it short: the depth is handled by iterating, display_element calls itself until the end or the given depth parameter.

Leave a Comment