How to group pdoResources by month and some TV value

To group the result by year and month, the easiest solution is probably to write a custom snippet that calls pdoResources and then processes the result further.

Something like this might work in your case:

<?php
// execute the snippet "pdoResources" and return the result as raw data
$data = $modx->runSnippet('pdoResources', [ 
    'parents' => 43, // change this to the actual value
    'includeTVs' => 'performance_date,performance_title',
    'sortby' => '{"YEAR(performance_date)":"ASC","MONTH(performance_date)":"ASC","performance_title":"ASC"}',
    'return' => 'data'
]);

$fmt = new IntlDateFormatter('en_US', null, null); // for formatting the date (in the subheading)
$fmt->setPattern('MM.yyyy');
$current_month_year = "";
$output = [];
foreach ($data as $item) {
    $month_year = strtotime($item['tv.performance_date']); // get the timestamp for the performance date
    $month_year = $fmt->format($month_year); // format the date
    if ($current_month_year != $month_year) { // the value has changed -> output a subheading
        $current_month_year = $month_year;
        $output[] = '<h3>' . $month_year . '</h3>';
    }
    $output[] = $modx->getChunk('tplPerformance', $item); // parse a result using the chunk 'tplPerformance'
}
return implode("\n", $output);
1 Like