Continuing the discussion from pdoResources where clause:
Thank you for the feedback, you helped enough to get a working solution. I used a snippet in the end as a value on passed on the URL can override the choice or pull it from the TV – here is the code in case it is of use to someone else:
<?php
$get = htmlspecialchars($_GET["discipline"]);
$id = $modx->resource->get('id');
$tv = $modx->resource->getTVValue('discipline');
if (!empty($get)) {
$sql = 'Discipline==%' . $get .'%';
} else {
$d = explode(",", $tv);
$c = count($d);
if ($c == 1) {
$sql = 'Discipline==%' . $tv .'%';
} else {
$sql = 'Discipline==%' . $d[0] .'%';
for ($x = 1; $x < $c; $x++) {
$sql .= '||Discipline==%' . trim($d[$x]) .'%';
}
}
}
$params = array(
'parents' => '14',
'includeTVs' => 'Discipline,Profile-BusinessCard',
'tpl' => 'pdoresources-listmatchingdiscipline.tpl',
'tvFilters' => $sql,
'limit' => '10',
'depth' => '0',
'sortby' => 'RAND()',
'where' => '{"id:!=":"' . $id . '"}',
'showLog' => '0',
);
#$output = "<br>GD=" . $get . "<br>TG=" . $tv . "<br>ID=" . $id . "<BR>" . $sql . PHP_EOL . var_dump($params);
$output .= $modx->runSnippet('pdoResources', $params);
return $output;