I tried Bobray's code again, and this time it works!
It might have been a missing ; as sottwell suggested anyway.
Thank you very much!
You're welcome.
FYI, the reason getParentIds() didn't work is that it doesn't accept a typical MODX 'where' array. The second argument is depth and the third is an array of options. The only option getParentIds() responds to is 'context'.
Hello again
I am working now with Bobrays code, and I have a new question related to this, so I keep it in the same thread.
It is about the order of the children.
I have children with the ID's 11,12,13,14,15,16,17,18, 19
Bobray's code returns: 14,15,16,11,13,12,17,18,19
I have tried to change their order in the file-tree, but this does not change the output.
I would very much like to reflect the file-tree order in my snippet-output.
Is that possible and how?
All the best
if you are talking about the order in the resource-tree, this is ordered by menuindex.
Try this:
$parentDoc = $modx->getObject('modResource', 5);
if ($parentDoc) {
$c = $modx->newQuery('modResource');
$c->where(array(
'published' => 1,
'searchable' => 1,
'deleted' => 0,
));
$c->sortby('menuindex');
$children = $parentDoc->getMany('Children', $c);
foreach ($children as $child) {
$output .= $child->get('pagetitle');
}
} else {
$output = 'Parent not found';
}
return $output;
Yes, thank you very much!