<?php /* build a query to get Resources with a given parent that are published and not deleted */ $query = $modx->newQuery('modResource', array('parent' => $id, 'deleted' => false, 'published' => true)); /* get the modResource objects with the given parent */ $children = $modx->getCollection('modResource', $query); /* loop through the children and push the id onto $resourceIds */ $resourceIds = []; $i=0; foreach ($children as $child) { $resourceIds []= $child->get('id'); } return $resourceIds[$number];
This question has been answered by Bruno17. See the first response.
<?php /* build a query to get Resources with a given parent that are published and not deleted */ $query = $modx->newQuery('modResource', array('parent' => $id, 'deleted' => false, 'published' => true)); $query->sortby('menuindex'); $query->limit(1,$number); /* get the modResource objects with the given parent */ $resourceID = 0; if ($child = $modx->getObject('modResource', $query)){ $resourceID = $child->get('id'); } return $resourceID;