We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12682
    • 4 Posts
    Is it possible to have getResources to sort by a template variable of the resources? I’m have ’Events’ resources that have an ’event_date’ TV. I would like to order the listing of these events by that TV rather than by publishedon or createdon etc.

    I’ve tried several attempts at the call, including:
    [tt][[!getResources? &parents=`20` &includeTVs=`1` &limit=`20` &sortBy=`[[+tv.event_date]]` &tpl=`events_listing_preview`]][/tt]
    and
    [tt][[!getResources? &parents=`20` &includeTVs=`1` &limit=`20` &sortBy=`+tv.event_date` &tpl=`events_listing_preview`]][/tt]
    and
    [tt][[!getResources? &parents=`20` &includeTVs=`1` &limit=`20` &sortBy=`event_date` &tpl=`events_listing_preview`]][/tt]

    But none work.... If it’s not currently possible to use TV’s, could someone point me in a direction of how I can modify the getResource snippet to allow for that functionality?

    Thanks in advance
      • 22303 MODX Staff
      • 10,725 Posts
      getResources does not currently support this, but I will look into added this feature with some other feature additions (i.e. sorting by multiple columns).
        • 12682
        • 4 Posts
        Thanks for the information! That’s unfortunate, but at least now I know I wasn’t going crazy ;-) I’ll just use the publishedon field instead for now. Looking forward to the day that those advanced sorting features make there way into the snippet!
          • 26039
          • 4 Posts
          I know this has been a while, but has there been any progress on being able to sort by template variables? I’m building a clothing shop and I need to be able to sort my pages by size, price etc...

          Many thanks.
            • 9849
            • 74 Posts
            Almost the same here wink
              • 22303 MODX Staff
              • 10,725 Posts
              FYI:

              Please note that I have released 1.2.0-pl of getResources that now allows sorting by a single raw template variable value. Here is an example of usage:
              [[!getResources? &parents=`0` &sortbyTV=`eventDate` &sortdirTV=`ASC` &sortby=``]]

                • 4971
                • 964 Posts
                Why is &sortBy empty?
                  Website: www.mercologia.com
                  MODX Revo Tutorials:  www.modxperience.com

                  MODX Professional Partner
                  • 22303 MODX Staff
                  • 10,725 Posts
                  Quote from: charliez at Sep 25, 2010, 05:28 PM

                  Why is &sortBy empty?
                  Because the default sortBy value is publishedon, and unless you want to also sort by publishedon DESC, this will prevent the additional sort criteria from being applied. It doesn’t have to be empty, but I wanted to show a simple sortbyTV ONLY example and at the same time let others know that you can now have an empty sortby property, to allow natural / explicit ordering of results (also a new feature of v1.2.0-pl.
                    • 4971
                    • 964 Posts
                    Thanks Jason!
                      Website: www.mercologia.com
                      MODX Revo Tutorials:  www.modxperience.com

                      MODX Professional Partner
                      • 10702
                      • 107 Posts
                      Is it also possible to sort the resources by a TV which is located in that resource containing the command [[getResources]]?

                      That would be great for my purpose...