I’ve set up a short collection called ‘locations’. I added some entries and activated “Custom sortable entries”. Then I ordered the items and also added a hirarchie.
I fetch the collection in php:
$arrPostList = cockpit(‘collections’)->find(‘locations’, [
‘sort’ => [‘category’ => 1, ‘_o’ => 1],
I expected the result to be like
but what I get is different:
any ideas or is this kind of sorting not implemented as of now?
OK, I see the problem and I’m not sure, if I can help you.
Nesting entries works with adding a numeric key _o, that starts with 0 in each nesting stage and a parent key _pid with the parent _id key. So entry1, entry2 and entry4 have _o = 0, entry3 has _o = 1. So the sorting works correct with the underlying logic.
I don’t see a useful generic solution to this, because everyone might expect different results when sorting hierachical entries.
If you look at the api controller, hierarchical entries are converted to a tree before sending the output, but only if they aren’t sorted:
You could do the sorting yourself after you get the result from the database or you could think about restructuring your data, e. g. into multiple collections with collection-links…