We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38004
    • 96 Posts
    Struggling a little to get my head around using geResources to only show posts with a certain tag.

    I haven't had to do this since the days of Ditto on Evo, so am more than a little rusty.


    My basic call is:
    [[!getResources? &parents=`4` &limit=`5` &tpl=`blogPost` &includeContent=`1` &showHidden=`1`]]


    Presumably I need to add some code telling it to include the tv 'tags' to process that tv, and to only display certain tags.

    As anyone got an example of this?

    Thanks
      • 30585
      • 833 Posts
      You need to use tvfilters. Here's how:

      [[!getResources? &parents=`4` &limit=`5` &tpl=`blogPost` &includeContent=`1` &showHidden=`1` &tvFilters=`tags==%[[*customtag]]%`]]
      


      This would force getResources to only return resources that contain the tag customtag.

      If you want more than one tag, you would use the or filter:

      [[!getResources? &parents=`4` &limit=`5` &tpl=`blogPost` &includeContent=`1` &showHidden=`1` &tvFilters=`tags==%[[*customtag]]%||tags==%[[*customtag2]]%||`]]
      


      The percentage sign (%) searches for the exact values.

      More on this on the official getResources documentation page.

      You should probably call your getResources uncached or use a cache manager extra like getCache. This could speed up the pageload for your users and your server will buy you a beer if you do that. [ed. note: treigh last edited this post 13 years, 5 months ago.]
        A MODx Fanatic
        • 38004
        • 96 Posts
        Thanks. That works a treat.

        I'll take a look at getCache.
          • 30585
          • 833 Posts
          Glad it worked.

          getCache is also super straightforward.

          You can use it like this:
          [[!getCache? &cacheExpires=`1200` &element=`getResources` &parents=`4` &limit=`5` &tpl=`blogPost` &includeContent=`1` &showHidden=`1` &tvFilters=`tags==%[[*customtag]]%`]]
          

          Always call it uncached and feel free to specify your preferred cache expiry time.

          Good luck!
            A MODx Fanatic