You could do it with two getResources calls, but I would do something like this (off the top of my head and untested):
$tvId = 12; /* change this to the ID of the category TV */
/* Get Management docs */
$tvrs = $modx->getCollection('modTemplateVarResource', array('tmplvarid' => $tvId, 'value' => 'Management'));
foreach ($tvrs as $tvr) {
$docs[] = $tvr->get('contentid');
}
$c = $modx->newQuery('modResource');
$c->where(
array('id:in' => $docs)
);
$c->sortby('pagetitle', 'ASC');
$managementDocs = $modx->getCollection('modResource', $c);
$output = '<h3>Management</h3><ul>';
foreach ($managementDocs as $doc) {
$output .= '<li>' . $doc->get('pagetitle'). '</li>';
}
$output .= '</ul>';
/*** Get Staff docs */
$tvrs = $modx->getCollection('modTemplateVarResource', array('tmplvarid' => $tvId, 'value' => 'Staff'));
foreach ($tvrs as $tvr) {
$docs[] = $tvr->get('contentid');
}
$c = $modx->newQuery('modResource');
$c->where(
array('id:in' => $docs)
);
$c->sortby('pagetitle', 'ASC');
$staffDocs = $modx->getCollection('modResource', $c);
$output = '<h3>Staff</h3><ul>';
foreach ($staffDocs as $doc) {
$output .= '<li>' . $doc->get('pagetitle'). '</li>';
}
$output .= '</ul>';
This should only take four queries. It's probably possible to use getCollectionGraph() or a join to do it in two queries, but I'm too tired to work it out. The code above will be *way* faster than doing it with getResources, which would make many more queries.
You could also use a Tpl chunk to format the output, but it would slow things down slightly by adding a call to $modx->getChunk() for each resource. If you need to have a link to each resource, you can do something like this inside the document loop:
$url = $modx->makeUrl($doc->get('id'), "", "", "full");
$output .= '<li><a href="' . $url . '">' . $doc->get('pagetitle'). '</a></li>';
You could also shorten the code significantly (with little or no change in the speed) by putting a getDocs() function at the top, passing it the category, and having it return the output.
That would look like this:
function getDocs($category) {
$tvId = 12; /* change this to the ID of the category TV */
$tvrs = $modx->getCollection('modTemplateVarResource', array(
'tmplvarid' => $tvId,
'value' => $category
));
foreach ($tvrs as $tvr) {
$docs[] = $tvr->get('contentid');
}
$c = $modx->newQuery('modResource');
$c->where(
array('id:in' => $docs)
);
$c->sortby('pagetitle', 'ASC');
$staffDocs = $modx->getCollection('modResource', $c);
$output = '<h3>' . $category . '</h3>
<ul>';
foreach ($staffDocs as $doc) {
$output .= '<li>' . $doc->get('pagetitle') . '</li>';
}
$output .= '
</ul>';
return $output;
}
return getDocs('Management') . getDocs('Staff');
Important: None of this will work if any of the TV values are inherited or hold the default value of the TV.