$mySiblingObjs=$myParentObj->getMany('Children');
foreach($mySiblingObjs as $mySibObj){
print("<hr>Sib from foreach loop<br>");
print_r($mySibObj->toArray());
}
This question has been answered by multiple community members. See the first response.
Dragging and dropping to reorder the resources does change the Menu Index. That would be the field you would want to sort by.Great! I over-contrived and under-tested by zeroing them then only moving them up
$query = $modx->newQuery('modResource'); /* any class key here */
$query->where(array(
'published' => 1,
'deleted' => 0,
));
$query->sortby('menuindex', 'ASC'); // or 'DESC'
$mySiblingObjs = $myParentObj->getMany('Children', $query);$parentId = $modx->resource->get('parent');
$query = $modx->newQuery('modResource');
$query->where(array(
'published' => 1,
'deleted' => 0,
'parent' => $parentId,
));
$query->sortby('menuindex', 'ASC'); // or 'DESC'
$mySiblingObjs = $modx->getCollection('modResource', $query);FYI, you can also provide criteria as a second argument to the getMany() call (or any xPDO get() method that gets multiple objects).I did get those working in part referencing Bob's Guide (that's you), but in my haste I omitted deleted. It will take me a few more weeks to get back up to speed and I am very appreciative of both you and Shawn Wilkerson in text and online. I am getting new folks up to speed so I actually have to relearn a bit including 2.x updates. We'll walk through both approaches- I'm partly trying to identify which will maintain best with high turnover staff (they keep graduating) and my tendency to only focus on PHP and MODX every two years (when the related course is offered). Thanks for your followup!
... $mySiblingObjs = $myParentObj->getMany('Children', $query);
You could also do this, which might be faster since there's no query to get the parent object:
$parentId = $modx->resource->get('parent'); $query = $modx->newQuery('modResource'); $query->where(array( 'published' => 1, 'deleted' => 0, 'parent' => $parentId, ));
$myQuery = $modx->newQuery('modResource');
$myQuery->where(array(
'published' => 1,
'deleted' => 0,
'parent' => $modx->resource->get('parent')
));
$myQuery->sortby('menuindex', 'ASC');
$mySiblingObjs = $modx->getCollection('modResource', $myQuery);
I do like the contrast between walking the object with $myParentObj->getMany() and a composed but otherwise (semi) independent query with $modx->getCollection(). Happy to hear advice, preferences etc. as each seems a reasonable approach.