Count all Rescources in tree

Hello,

I am thinking about how I can count all resources in a tree with special options.
For example published=1, deleted=0, isfolder=0.

With getChildIds I dont get the right values.

The Resource structure, with only resources as container. But I want only count resources isfolder=0 inside a folder structure.

How could I solve this?
Own snippet?

Thank you in advance

Bye
Chris

Yes.

With the ids from getChildIds make a new query to filter by isfolder or deleted etc.
Something like this:

<?php
$ids = [1,2,3,4,5,6,7];
$amount = $modx->getCount('modResource', ['id:IN' => $ids, 'isfolder' => 0]);
return $amount;

thank you. thats great.

I thinking about additional requirement.

How could I collect Information for a tree to get all folder and the count of resources inside the folder and sort it?

Thank you in advance

Bye
Chris

What counts as a resource inside the folder? Only direct children or also children deeper in the hierarchy? Should another folder inside this folder also be counted?

yes, recursive count all child resources without container=0 and if a resource is a folder count its childs too.

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.