We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 39961
    • 25 Posts
    Hi
    I'm trying to sort and display MIGX items (events) that are newer than the current date - does anyone know how to do this; surely this is just a syntax issue but I can't find how to do it anywhere. All below works apart from '&where...' bit in the middle...

    [[getImageList? &tvname=`Events` &tpl=`EventLoopTpl` &where={expires:>":"NOW()"} &sort=`[{"sortby":"expires","sortdir":"ASC"}]` &limit=`2` ]]


    Help much appreciated!
    Gareth

    This question has been answered by doglegdesign. See the first response.

    • discuss.answer
      • 39961
      • 25 Posts
      Managed to sort it! Bit of a syntax issue also, but all resolved and working it would appear...

      I created a snippet called RANow and matched the output format of MIGX's date output:
      <?php
      return date("Y-m-d H:i:s");

      ...I then used that in the where clause:
      [[getImageList? &tvname=`Events` &tpl=`EventLoopTpl` &where=`{"expires:>":"[[RANow]]"}` &sort=`[{"sortby":"expires","sortdir":"ASC"}]` &limit=`2` ]]

      Hopefully this will help someone out - if anyone knows another way, please feel free to add.
      Thanks
        • 4172
        • 5,888 Posts
        if you dates are stored in this format: yyyy-mm-dd HH:MM:SS

        sorting should work like you have it.

        Filtering should work this way:

        &where=`{"expires:>":"[[!now]]"}`


        the snippet 'now':

        return strftime('%Y-%m-%d %H:%M:%S');

          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 4172
          • 5,888 Posts
          make sure, you call everything uncached
          [[!getImageList]]
          and
          [[!RANow]]
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 39961
            • 25 Posts
            Hi Bruno
            Thanks for your reply - looks similar to where I eventually got to.
            Cached version noted! smiley
            Gareth
              • 38705
              • 101 Posts
              How should i put this in a cmp? if I add
              {"expires:>":"[[!now]]"}
              within the CMP's MIGXDB-settings Where field, it doesn't seem to be working?
                Addict since 2012....
                • 4172
                • 5,888 Posts
                maybe, you will need to use the cached tag in this case, because there isn't any caching. Only cached tags get parsed here, AFAIK.

                {"expires:>":"[[now]]"}
                
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 38705
                  • 101 Posts
                  (sorry doglegdesign for hyjacking your thread)

                  Hi Bruno,
                  thanx for the feedback.

                  However I can not get this to work in a MigxDB-CMP.

                  if i enter
                  {"expires:>":"2017-01-11 00:00:00"}

                  i get perfect results. but trying to proces this snippet in it it won't work.
                  Something in the CMP?

                  Also see my question here: https://forums.modx.com/thread/101580/where-clause-in-loopcollection-and-in-cmp#dis-post-547907
                    Addict since 2012....