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

    I’ve tried a few examples I’ve seen around the forums, but can’t seem to get this to work at all.

    I want to pop in a where statement on getResources to show only items published in the last three days.

    Before I got involved with the ’3 days ago’ thing I thought I’d at least grasp a simple where statement on a set date.

    However it just seems to show all results.

    (I was going to paste my latest attempt but the modx menus got in the way again and I ended up clicking and leaving the page - d’oh)
      • 14437
      • 31 Posts
      I'm looking for the same kinda thing.

      The goal is to display a list of the 'most read' resources the last xx days

      I made a plugin 'ViewCount' to count pageviews, they're stored in a TV.

      So I need to make the call 'select resources where published on is max xx days ago' and then sort by the ViewCount TV, then limit output by x.

      The question is: how ? smiley
      • If you want to display the top X posts you could use something like: http://forums.modx.com/thread/70794/top-5-read-documents

        If I recall getResources can filter/sortby the views TV to display the "results" if desired.
          Patrick | Server Wrangler
          About Me: Website | TweetsMODX Hosting
          • 14437
          • 31 Posts
          The top X posts is not really the problem, figured that one out.

          Making getResources to select only the resources from the last X days and THEN sorting them is my question.
          • Assuming you have a Snippet to return a unix timestamp with which to compare against the publishedon field, e.g.:

            <?php
            $ts = !empty($input) ? strtotime($input) : time();
            return (string) $ts;
            


            Then simply add a where property like so, say if you want to select from everything published within the last month:
            &where=`{"publishedon:>":[[time? &input=`-1 month`]]}`
              • 14437
              • 31 Posts
              Wicked! that does the job! it works!
              Thanks a lot!

              Not only the CMS rocks, so does the community.

                • 14437
                • 31 Posts
                You can't use a TV instead of 'publishedon' right?

                To quote:

                The TV's are not joined and thus you cannot use that condition in the where clause. Others have requested this feature and it will be added soon.
                • Correct; it's not currently possible to reference TV fields in the where clause, or use comparison operators other than LIKE to filter them. But you can sort by date TV fields using the sortbyTV and sortbyTVType properties and limit the number of results.
                    • 27106
                    • 147 Posts
                    Anyone want to suggest a way to return posts that are not from, say, the current year?
                      David Walker
                      Principal, Shorewalker DMS
                      Phone: 03 8899 7790
                      Mobile: 0407 133 020
                      • 8548
                      • 104 Posts
                      Quote from: opengeek at Oct 26, 2011, 04:26 PM
                      Assuming you have a Snippet to return a unix timestamp with which to compare against the publishedon field, e.g.:

                      <!--?php
                      $ts = !empty($input) ? strtotime($input) : time();
                      return (string) $ts;
                      


                      Then simply add a where property like so, say if you want to select from everything published within the last month:
                      &where=`{"publishedon:>":[[time? &input=`-1 month`]]}`


                      Great thanks, I've been looking for this all day... knew is was something I was misign :

                      cheers [ed. note: Egam last edited this post 10 years, 5 months ago.]