Код сниппета:
<?php
$searchCaption = trim($modx->getOption('author', $scriptProperties, ''));
$tpl = $modx->getOption('tpl', $scriptProperties, 'item');
$limit = (int)$modx->getOption('limit', $scriptProperties, 12);
$parents = $modx->getOption('parents', $scriptProperties, 1453);
$sortby = $modx->getOption('sortby', $scriptProperties, 'publishedon');
$sortdir = $modx->getOption('sortdir', $scriptProperties, 'DESC');
if (empty($searchCaption)) {
return 'Автор не указан';
}
$tv = $modx->getObject('modTemplateVar', ['name' => 'artAuthor']);
if (!$tv) {
return 'TV artAuthor не найдена';
}
$tvId = $tv->get('id');
$optionsString = $modx->runSnippet('authorIDs');
$tvValue = null;
if (!empty($optionsString)) {
$pairs = explode('||', trim($optionsString));
foreach ($pairs as $pair) {
$pair = trim($pair);
if (empty($pair)) continue;
if (strpos($pair, '==') !== false) {
list($caption, $value) = array_map('trim', explode('==', $pair, 2));
if ($caption === $searchCaption) {
$tvValue = $value;
break;
}
}
}
}
$pdoParams = [
'parents' => $parents,
'includeTVs' => 'artAuthor',
'where' => json_encode([
'TVartauthor.tmplvarid' => $tvId,
'TVartauthor.value' => $tvValue
]),
'join' => '[{"alias":"TVartauthor","left":false,"table":"modTemplateVarResource","on":"TVartauthor.contentid = modResource.id AND TVartauthor.tmplvarid = '.$tvId.'"}]',
'sortby' => $sortby,
'sortdir' => $sortdir,
'limit' => $limit,
'tpl' => $tpl,
'showUnpublished' => 1,
'showDeleted' => 0,
'pageVarKey' => 'page',
// 'showLog' => 1,
];
$output = $modx->runSnippet('pdoPage', $pdoParams);
return $output ?: 'no';