We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36924 ☆ A M B ☆
    • 298 Posts
    the getRelated snippet by default sorts the output in descending order, from newest to oldest. How do you achieve the opposite: ascending from Oldest to Newest?

    thanks in advance.
      • 3749
      • 24,544 Posts
      Try this:

      &fieldSortDir=`asc`


      or if you're sorting by a TV:

      &tvSortDir=`asc`
        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
        • 36924 ☆ A M B ☆
        • 298 Posts
        Thanks for the response.

        I've tried &fieldSortDir=`asc` before posting. Doesn't solve it. I'm not using TV to sort either
          • 3749
          • 24,544 Posts
          That should definitely work according to the docs.

          Are you sending a &fieldSort property? It may not look at the direction property without that.

          Also, the sort directions in xPDO are uppercase, so try 'ASC'.

          Strangely, the xPDO query default is 'ASC' but the getRelated default is 'desc'. By default, getRelated sorts on createdon, is that what you're using? [ed. note: BobRay last edited this post 13 years 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
            • 36924 ☆ A M B ☆
            • 298 Posts
            you mean createdon. The docs state the &fieldSort default is used if not specified, so I didn't declare any.

            tried the uppercase: ASC without any difference in output.
              • 3749
              • 24,544 Posts
              Yes, I did mean createdon. Did you try adding the &fieldSort property? It's worth a shot, imo, since nothing else has worked.

              BTW, looking at the code, I don't see any way what you're doing could not work.

              The only other things I can think of are a missing question mark in the snippet tag, not calling the snippet uncached after making a change, and a misspelled property name.
                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
                • 36924 ☆ A M B ☆
                • 298 Posts
                explicitly calling &fieldSort=`createdon`, I tried that too.

                I read https://forums.modx.com/thread/?thread=71009&page=1 and it doesn't seem to support sorting. At least in the way we understand it. And kind of strange.
                  • 3749
                  • 24,544 Posts
                  Yes, apparently it doesn't support sorting.

                  What exactly are you trying to do? Maybe there's another way.
                    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
                    • 36924 ☆ A M B ☆
                    • 298 Posts
                    I have a set of resources under a parent. Now those resources actual hold the profiles of the company's management team. They were input starting from the highest hierarchy but since getRelated (by defualt) sorts by placing the newest resources at the top of the list, you have the most junior team member at the top and the bosses at the base (which is not the other it should be).

                    getResources would have achieve this sorting but I don't know why it just doesn't work for me any more as it used to. I get no output (this has occured on my last three MODx projects). So I ran to getRelated as alternative.
                      • 3749
                      • 24,544 Posts
                      OK, I think getting getResources to work would be a much better plan. Tell getResources to sort by menuindex and drag them to the order you want in the tree.

                      If your getResources tag is not working at all, paste it here.
                        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