Turns out it was fairly easy to adapt getResourceTag for this purpose.
In your template:
[[!getRelated? &parents=`6` &tpl=`tagTpl` &tagKey=`my_tags` &tags=`[[*my_tags]]`]]
And the snippet code (getRelated):
<?php
/**
* getRelated
* Based on getResourcesTag by Shaun McCormick
*
*/
$output = '';
$tagKey = $modx->getOption('tagKey',$scriptProperties,'tags');
$tags = $modx->getOption('tags',$scriptProperties,'');
if (!empty($tags)) {
// explode tags into array
$tags = $modx->stripTags($tags);
$tags = explode(',',$tags);
// convert to tvFilters
$tvFilters = array();
foreach ($tags as $tag) {
$tvFilters[] = $tagKey.'==%'.$tag.'%';
}
$scriptProperties['tvFilters'] = implode($tvFilters,'||');
// send to getResources
$elementObj = $modx->getObject('modSnippet', array('name' => 'getResources'));
if ($elementObj) {
$elementObj->setCacheable(false);
$output = $elementObj->process($scriptProperties);
} else {
return 'You must have getResources downloaded and installed to use this snippet.';
}
}
return $output;
The snippet acts as a wrapper for getResources so you can use all properties available for that snippet with this one too.
To exclude the current document from results: &resources=`-[[*id]]`
Note that tags are searched using the ’or’ operator, so if the current document’s tags are ’pig, horse, cow’ it will return a list of any documents including the tags ’pig’ or ’horse’ or ’cow’.
Let me know if it works for you...