the benefit of using
$c->where("CONCAT('||',category,'||') LIKE '%||" . $cat . "||%'", xPDOQuery::SQL_AND);
is exactly that, what you are looking for.
Searching for exact words in delimited field-contents.
If you have in your TVs:
page1: box||container
page2: cardboard box||another one
page3: boxing
page4: container||box||another one
and you are searching for 'box'
this will find page1 and page4
no need to have another TV-type
of course if you have comma-delimited - TV-lists where you want to search in you can do
$c->where("CONCAT(',',category,',') LIKE '%," . $cat . ",%'", xPDOQuery::SQL_AND);
<?php
$tagKeyVar = $modx->getOption('tagKeyVar', $scriptProperties, 'key');
$tagKey = (!empty($tagKeyVar) && !empty($_GET[$tagKeyVar])) ? $_GET[$tagKeyVar] : $modx->getOption('tagKey', $scriptProperties, 'tags');
$tagRequestParam = $modx->getOption('tagRequestParam', $scriptProperties, 'tag');
$tag = $modx->getOption('tag', $scriptProperties, urldecode($_GET[$tagRequestParam]));
if (!empty($tag)) {
$tag = $modx->stripTags($tag);
if ($tv = $modx->getObject('modTemplateVar', array('name' => $tagKey))) {
$c = $modx->newQuery('modTemplateVarResource');
$c->where("CONCAT(',',value,',') LIKE '%," . $tag . ",%'", xPDOQuery::SQL_AND);
if ($collection = $tv->getMany('TemplateVarResources',$c)){
$ids = array();
foreach ($collection as $object){
$ids[] = $object->get('contentid');
}
$where = array('id:IN'=>$ids);
$scriptProperties['where'] = $modx->toJson($where);
}
}
}
return $modx->runSnippet('getResourcesTag',$scriptProperties);
[[!tagLister? &tv=`articlestags` &target=`[[*id]]` ]] [[!getResourcesTagExact? &showHidden=`1` &parents=`[[*id]]` &tpl=`sample.ArticleRowTpl` &includeTVs=`1` &tagKey=`articlestags`]]
This should do it:
snippet 'getResourcesTagExact':
<!--?php $tagKeyVar = $modx--->getOption('tagKeyVar', $scriptProperties, 'key'); $tagKey = (!empty($tagKeyVar) && !empty($_GET[$tagKeyVar])) ? $_GET[$tagKeyVar] : $modx->getOption('tagKey', $scriptProperties, 'tags'); $tagRequestParam = $modx->getOption('tagRequestParam', $scriptProperties, 'tag'); $tag = $modx->getOption('tag', $scriptProperties, urldecode($_GET[$tagRequestParam])); if (!empty($tag)) { $tag = $modx->stripTags($tag); if ($tv = $modx->getObject('modTemplateVar', array('name' => $tagKey))) { $c = $modx->newQuery('modTemplateVarResource'); $c->where("CONCAT(',',value,',') LIKE '%," . $tag . ",%'", xPDOQuery::SQL_AND); if ($collection = $tv->getMany('TemplateVarResources',$c)){ $ids = array(); foreach ($collection as $object){ $ids[] = $object->get('contentid'); } $where = array('id:IN'=>$ids); $scriptProperties['where'] = $modx->toJson($where); } } } return $modx->runSnippet('getResourcesTag',$scriptProperties);
call it like that in an articles-container:
[[!tagLister? &tv=`articlestags` &target=`[[*id]]` ]] [[!getResourcesTagExact? &showHidden=`1` &parents=`[[*id]]` &tpl=`sample.ArticleRowTpl` &includeTVs=`1` &tagKey=`articlestags`]]
<!--?php $tagKeyVar = $modx--->getOption(
$tagKeyVar = $modx->getOption(
[[!migxLoopCollection?
&classname=`modTemplateVarResource`
&where=`{"tmplvarid":"20","1":[
{"value":"[[!#get.tag]]"},
{"OR:value:LIKE":"%||[[!#get.tag]]||%"},
{"OR:value:LIKE":"[[!#get.tag]]||%"},
{"OR:value:LIKE":"%||[[!#get.tag]]"}
]}`
&tpl=`@CODE:[[+contentid]]`
&outputSeparator=`,`
&toPlaceholder=`resource_ids`
]]
[[!migxLoopCollection?
&classname=`modTemplateVarResource`
&where=`{"tmplvarid":"20","1":[
{"value":"[[!#get.tag]]"},
{"OR:value:LIKE":"%,[[!#get.tag]],%"},
{"OR:value:LIKE":"[[!#get.tag]],%"},
{"OR:value:LIKE":"%,[[!#get.tag]]"}
]}`
&tpl=`@CODE:[[+contentid]]`
&outputSeparator=`,`
&toPlaceholder=`resource_ids`
]]
[[!pdoResources?
&parents=`0`
&includeTVs=`tvA, tvB, tvC`
&processTVs=`1`
&prepareTVs=`1`
&showHidden=`1`
&resources=`[[!+resource_ids]]`
&tpl=`tpl_row`
&depth=`10`
]]