I’m going to make this as clear as I can, understanding only dimly what I’m doing
I have a snippet that displays a list of resources in groups - let’s call them fruits and vegetables. Now, ’type’ (fruit or vegetable) is one template variable; there are also other template variables, one of which is "calories per serving" (cps). I want to group the resources by type, then
sort the individual resources by cps.
Here’s the code that grabs all the resources for one group:
$c = $modx->newQuery('modResource');
$c->where('`modResource`.`id` IN ('.$query.')');
$resources = $modx->getCollection('modResource',$c);
This code is in a function that runs once for each group and accepts a variable called $query. Here’s the code where $query is set:
$query = 'SELECT DISTINCT `contentid` FROM `modx_site_tmplvar_contentvalues` WHERE `tmplvarid` = "5" AND `value` = '.$type;
In a misguided attempt to accomplish my goal, I concocted a much more complicated version of the above query, involving an inner join and an ORDER BY statement referencing the calories, which produced the result set in the desired order - the problem being, of course, that the IN statement in the xPDO query ignored the order of the contentids in the result set.
So, I understand how to select resources based on TV’s using an IN statement, but what about sorting those resources based on the values of other TV’s? Surely this is not beyond MODx/xPDO? It’s definitely beyond me