I too am trying to grab resources related to the current resource using tags. In my case, any resource with more than one tag is not filtered by getResources as expected. Resources with a single tag are filtered and output.
FYI - I have the latest getResources (1.4.0-pl - Sept 21, 2011)
My snippet grabs all tags of the current resource and feeds it to getResources as the tvFilter:
$output = "";
$tagslist = "";
$searchtags = "";
$resid = $modx->resource->get('id');
$searchtags = $modx->runSnippet('getResourceField', array(
'id' => $resid,
'isTV' => 1,
'field' => 'tags',
'processTV' => 1
));
if (empty($searchtags)) return "Resource ".$resid." has no tags";
$tagnames = explode(',',$searchtags);
$i = 0;
foreach ($tagnames as $tagname) {
if ($i == 0) { $tagslist .= "tags==".$tagname; $i++; }
else $tagslist .= "||tags==".$tagname;
}
$output = $modx->runSnippet('getResources', array(
'parents' => '159,137,138,176',
'includeTVs' => 1,
'processTVs' => 1,
'includeTVList' => 'tags',
'processTVList' => 'tags',
'tvFilters' => $tagslist,
'hideContainers' => 1,
'limit' => 10,
'sortby' => '{"publishedon":"DESC"}',
'tpl' => 'BlogPosts.relatedposts.Tpl'
));
if (empty($output)) $output .= "getResources did not find matching resources. Criteria <br>tvFilters = ".$tagslist;
return $output;
Here is an example:
Resource1 - tags(Sportsmanship)
Resource2 - tags(Sportsmanship,Coach)
Resource3 - tags(Starter)
Resource4 - tags(Starter,Substitute)
Resource5 - tags(Sportsmanship,Starter)
If I filter for Sportsmanship, only Resource1 is output.
If I filter for Starter, only Resource3 is output.
If I filter for Sportsmanship & Starter, only Resource1 and Resource3 is output.
If I filter for Coach or Substitute, no resources are output.
This is certainly not the behavior I expected. Can you spot something amiss here, have I misunderstood the purpose of tvFilters?