We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17329
    • 53 Posts
    Mark,

    It seems to me randomize does not work as expected with Ditto 2.0 final.
    I have a simple call that should give one random item in a folder:

      [!Ditto? &parents=`42` &randomize=`1` &summarize=`1` &tpl=`aTpl` !]

    What I see is that it first fetches one item and then randomize the result so that I aways get the same.
    I tried to increase the number of items retrieved and indeed it first retrieves n most recent items using datecareated and then randomize the order of those resulting items.

    What I would expect is to get a random item amongst those available. It seems to me it was working that way with previous ditto.

      • 18397
      • 3,250 Posts
      Ok, it should be fixed in SVN. You can try out a copy from here: http://www.modxcms.com/ditto_download.html
      Let me know if it fixes the issue for you.
        • 17329
        • 53 Posts
        The new version does fix the problem.
        Thanks
          • 7455
          • 2,204 Posts
          Somhow it does not work for me, I downloaded from the link above.

          this is my call
          [!Ditto? &parents=`30,31,32` &tpl=`DittoTmpl_randomactueel` &randomize=`1`&summarize=`1` !]
          


          it shows the same item each time, its the last document made.

          dimmy
            follow me on twitter: @dimmy01
            • 18397
            • 3,250 Posts
            Dimmy, did you update all of the files as well?
              • 25663 MODX Staff
              • 12,272 Posts
              I just downloaded the latest head as well, and find it to not be working properly. WIth the following call:
              [!Ditto? &parents=`38` &tpl=`home-page-quote` &randomize=`1` &limit=`1`!]

              I always get the same result.


              Interestingly, in sleuthing to see if the randomize parameter was flipped, with the following call:
              [!Ditto? &parents=`38` &tpl=`home-page-quote` &randomize=`0` &limit=`1`!]

              I get ALL the results (limit parameter ignored completely).

              Something strange is afoot at the Circle K...

                Ryan Thrash, MODX Co-Founder
                Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                • 18397
                • 3,250 Posts
                You can’t use &limit with &randomize because &limit will only retrieve one row while randomize needs all of the rows to randomly select one.
                  • 18397
                  • 3,250 Posts
                  Well, I’ll be darned... You can sortBy rand() in mySQL. Stay tuned for an update that uses this instead...
                    • 18397
                    • 3,250 Posts
                    Ok, done in SVN.


                    [NEW] &randomize now uses mySQL’s RAND() function for faster parsing and LIMIT support
                      • 25663 MODX Staff
                      • 12,272 Posts
                      Bingo ... works perfectly now Mark smiley

                      Now you can use Ditto for a simple ad management system ... tongue
                        Ryan Thrash, MODX Co-Founder
                        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me