We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21122
    • 153 Posts
    So close....Yet so far!!

    Well done for working on it though Lucas. Has the bug been submitted?
      • 33968
      • 863 Posts
      Yeah it’s been submitted and there appears to be a few people looking into it. Will post an update here if anything changes...
        • 21122
        • 153 Posts
        Thanks again for all your help Lucas, really, really appreciate it.
          • 20358
          • 10 Posts
          Awesome, thanks for the updates lucas. I applied your fix for #1 and we’re good to go there. I’ll keep my eye out for the bug fix on getResources. For the meantime, this at least gives me a way to apply a single sub-category, which is just fine for my purposes.

          Thanks again for taking the time to work on this!

          Swill
            • 36666
            • 19 Posts
            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?
              • 3749
              • 24,544 Posts
              The each element of the tvFilter parameter has the form:
              tvName==value


              Offhand, it looks like you're using 'tags' instead of the TV name (unless all your TVs are called "tags").
                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
                • 36666
                • 19 Posts
                I'm not sure I understand what you mean.

                The TV name is "tags". IE:




                and the value returned is a comma separated list of the "tags" associated with a resource.
                IE: "Sportsmanship,Batter,Runner,Batter-Runner"

                Here is some abbreviated output from getResources:
                Array
                (
                    [tpl] => 
                    [tvFilters] => tags==Sportsmanship
                    [parents] => 159,137,138,176
                    [id] => 177
                    [published] => 1
                    [parent] => 138
                    [tv.tags] => Sportsmanship
                )
                
                Array
                (
                    [tpl] => 
                    [tvFilters] => tags==Sportsmanship
                    [parents] => 159,137,138,176
                    [id] => 141
                    [published] => 1
                    [parent] => 138
                    [tv.tags] => Sportsmanship
                )


                When I specify &tvFilter=`tags==Sportsmanship` I get all resources where the Sportsmanship tag is the only tag. Other resources having multiple tags, including the Sportsmanship tag, are not output. IE: [tv.tags] => Sportsmanship,Batter

                getResourcesTag returns all resources with a specified tag, even those with multiple tags, but only provides the GET method using a single tag. I am trying to do something like:
                "tvFilters=`tags==Rules||tags==Batter||tags==Batter-Runner||tags==Runner||tags==Pitcher||tags==Catcher||tags==Coach` and have all resources with any of these tags defined to be selected for output.
                Perhaps I misunderstood the OR option of tvFilters?
                [ed. note: cp@pcs last edited this post 15 years, 1 month ago.]
                  • 3749
                  • 24,544 Posts
                  Ah, I see.

                  As you say, the actual value of one with multiple tags is a comma-separated list, which won't match the search string. AFAIK, the OR option allows you to filter by multiple TVs, not comma-delimited values in a single TV.

                  I don't know if there is a way to make it parse the autotag TV value. If not, it would be a good feature request.

                  There might be a way to use LIKE: in the criteria, otherwise you might have to do it with a custom snippet, which might be much faster anyway. [ed. note: BobRay last edited this post 15 years, 1 month ago.]
                    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
                    • 36666
                    • 19 Posts
                    I'll give it a whirl...
                      • 36666
                      • 19 Posts
                      It appears that changing the tvFilter criteria is all that is needed.

                      Instead of:
                      tvFilters=`tags==Sportsmanship||tags==Batter||tags==Coach`


                      I used
                      tvFilters=`tags==%Sportsmanship%||tags==%Batter%||tags==%Coach%`


                      I now get every resource having any of the tags assigned to the current resource.

                      Thanks BobRay for the clue about parsing the comma-separated string...