Suddenly the output changed, but I haven’t changed anything for a long time. Right now I couldn’t set a normal sequence. That all resources were derived from the categories, then from the next one. Now, for example, I have an incorrect conclusion and a number of resources are not in their categories at all
So what’s your sortby field?
In the code you posted it’s not specified and in the screenshot it’s menuindex.
Sorting only by menuindex doesn’t make much sense when you query the data from different folders. In each folder the menuindex values start with 0. So there are different resources with the same menuindex. The order of the resources with the same menuindex is not defined and is basically random.