Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find pages by depth #463

Open
Toutouwai opened this issue Oct 28, 2022 · 0 comments
Open

Find pages by depth #463

Toutouwai opened this issue Oct 28, 2022 · 0 comments

Comments

@Toutouwai
Copy link

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant