processwire-requests icon indicating copy to clipboard operation
processwire-requests copied to clipboard

Find pages by depth

Open Toutouwai opened this issue 2 years ago • 0 comments

Short description of the enhancement

It would be cool if we could find pages by depth (the number of parents).

Example:

$tier_three_pages = $pages->find("depth=3");

And this would potentially be a lot more efficient than looping over $page->children and $child->children when dealing with large numbers of descendants:

// I know it's possible to work out depth via $page->parents->count 
// but might as well have depth as a property if the parent count is going to be stored in the DB anyway
$min_depth = $page->depth + 1;
$max_depth = $page->depth + 2;
$children_and_grandchildren = $page->find("depth>=$min_depth, depth<=$max_depth");

Related forum topic: https://processwire.com/talk/topic/15105-why-isnt-there-a-page-level-property/

Toutouwai avatar Oct 28 '22 03:10 Toutouwai