We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19328
    • 433 Posts
    oh right, I understand now! But, this way the user will see the doublepipes when opening the resource again right? (I'm using autotag). And what if he chooses a tag from the list that already had double pipes, that might give problems when there are more pipes added?
      • 4172
      • 5,888 Posts
      the tag itself doesn't have the doublepipes,
      The doublepipe is just the delimiter for the tags (and other array-TV-values like checkboxes and listbox-multiple) in the db.
      The customer doesn't see them.
      The plugin would just add additional doublepipes at front and at the end of all the tags(which are allready delimited by doublepipes) and only, if they aren't allready there.
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 19328
        • 433 Posts
        oh aha now (I think) I understand. This is because the delimiter is not at the beginning of the first tag and the end of the last, am I correct? For autotag the delimiter is a comma though. I'm going to try if I can get this working, thanks!
          • 4172
          • 5,888 Posts
          ah, ok, then autotag seems to be a special thing and does need special handling and you would add a comma before the first and after the last tag.
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 37984
            • 215 Posts
            Quote from: Bruno17 at Feb 16, 2013, 12:18 AM
            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);





            Bruno - how would I implement this solution if I am using the Articles extra (tagging is powered by getResourcesTag & tagLister snippets). I have a specific problem similar to the above where pages tagged with "men" and "encouragement" are both being returned when the url includes "?tag=men". I need it to return only items tagged "men".
              Jesse Couch
              MODX Aficionado, Front-End Designer & Developer
              http://www.designcouch.com
              • 4172
              • 5,888 Posts
              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`]]
              
              [ed. note: Bruno17 last edited this post 10 years, 4 months ago.]
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 37984
                • 215 Posts
                Quote from: Bruno17 at Dec 25, 2013, 10:56 AM
                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`]]
                

                Unfortunately, this snippet causes the entire page render to fail (pure white screen, no content whatsoever).
                  Jesse Couch
                  MODX Aficionado, Front-End Designer & Developer
                  http://www.designcouch.com
                  • 3749
                  • 24,544 Posts
                  Is this really your code?

                  <!--?php
                   
                  $tagKeyVar = $modx--->getOption(


                  If so, make it just:

                  $tagKeyVar = $modx->getOption(
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 4172
                    • 5,888 Posts
                    And here is a solution, which we used today with migxLoopCollection to get exact results

                    get the ids with matching tags in TV with ID 20

                        
                        [[!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`
                        ]]


                    or, if you have a TV which stores commaseparated:

                        
                        [[!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`
                        ]]


                    List matching Resources:

                                    [[!pdoResources?
                                        &parents=`0`
                                        &includeTVs=`tvA, tvB, tvC`
                                        &processTVs=`1`
                                        &prepareTVs=`1`
                                        &showHidden=`1`
                                        &resources=`[[!+resource_ids]]`
                                        &tpl=`tpl_row`
                                        &depth=`10`
                                    ]]


                    [ed. note: Bruno17 last edited this post 10 years, 1 month ago.]
                      -------------------------------

                      you can buy me a beer, if you like MIGX

                      http://webcmsolutions.de/migx.html

                      Thanks!
                      • 5290
                      • 29 Posts
                      It's not very clear from the changelog and the manual hasn't yet been adjusted either, but since tagLister 1.1.7, the snippet getResourcesTag uses a parameter called &tagSearchType that allows you to match tags in 5 different ways:

                      • contains (default)
                      • exact
                      • beginswith
                      • endswith
                      • within

                      Bruno17's solutions is neat and very precise, but also rather complex. For most people, the new tagLister parameter will probably do just fine.
                        A computer program is a utilitarian typographer's dream - a functioning machine composed completely of type. (John Maeda)