processwire / processwire-requests

ProcessWire feature requests.
39 stars 0 forks source link

Find pages by depth #463

Open Toutouwai opened 1 year ago

Toutouwai commented 1 year ago

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/