Quote from: BobRay at Jun 20, 2010, 02:20 AM
To get the children of a document, sorted by Title:
$criteria = $modx->newQuery('modResource');
$criteria->where(array(
'parent' => $modx->resource->get('id'),
));
$criteria->sortby('pagetitle','ASC');
$children = $modx->resource->getMany('Children',$criteria);
Turns out this wasn’t exactly what I needed but it’s very close. What Bob’s code does is get all MODx resources sorted by page title along with their children. What I needed is all children sorted by a particular field (note these aren’t modx resources, they’re actually wordpress comments)
// Create a query for comments
$criteria = $wp->newQuery('Comments');
$criteria->where(array(
'comment_post_ID' => $post->get('ID'),
));
// Here is where to set the sort order
$criteria->sortby('comment_ID','ASC');
// $post is a single post object, analogous to a single MODx resource object
// Here we tell xpdo to get all comments of this post, using our custom criteria
$comments = $post->getMany('Comments',$criteria);
Thanks again bob for leading me in the right direction. The key is knowing how to build custom query objects.