We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16633
    • 116 Posts
    I am trying to use getResources to display a series of resources however I want to restrict it by the current year. I cannot seem to get it working, here is what I have I have tried

    [[!getResources? &parents=`43` &limit=`` &tpl=`NominationListTpl` &totalVar=`total_nonprofit` &tvFilters=`nominee_category==nonprofit,createdon:strtotime:date=`%Y`===2012`]]
    [[!getResources? &parents=`43` &limit=`` &tpl=`NominationListTpl` &totalVar=`total_nonprofit` &tvFilters=`nominee_category==nonprofit` &where=`{"createdon:strtotime:date=`%Y`:=":2011}`]]

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

    [ed. note: smashingred last edited this post 10 years, 8 months ago.]
      --
      Landon Poburan
      Web Designer and Developer

      http://www.categorycode.ca
      http://www.landonp.com
    • discuss.answer
      • 4172
      • 5,888 Posts
      I think you can try something like this:

      <?php
      
      //[[getYearArchive? &year=`2012` &parents=`100` &tpl=`myTpl`]]
      
      $where = $modx->getOption('where',$scriptProperties,false);
      $where = is_array($where) ? $where : $modx->fromJSON($where);
      
      $where[] = 'FROM_UNIXTIME(`createdon`,"%Y") = "'.$year.'"';
      
      $scriptProperties['where'] = $modx->toJSON($where);
      
      return $modx->runSnippet('getResources',$scriptProperties);
      


      or try to use getarchives from archivist
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 16633
        • 116 Posts
        Using that would I be able to use all the same parameters as getResources?
          --
          Landon Poburan
          Web Designer and Developer

          http://www.categorycode.ca
          http://www.landonp.com
          • 16633
          • 116 Posts
          That worked great! Thank you smiley
            --
            Landon Poburan
            Web Designer and Developer

            http://www.categorycode.ca
            http://www.landonp.com
          • I just enhanced this script a bit to use getPage. That way you can include the pagination functionality to it:

            $where = $modx->getOption('where',$scriptProperties,false);
            $where = is_array($where) ? $where : $modx->fromJSON($where);
             
            $where[] = 'FROM_UNIXTIME(`publishedon`,"%Y") = "'.$year.'"';
             
            $scriptProperties['where'] = $modx->toJSON($where);
            $scriptProperties['elementClass'] = 'modSnippet';
            $scriptProperties['element'] ='getResources';
            
            return $modx->runSnippet('getPage',$scriptProperties);
              Benjamin Davis: American web designer living in Munich, Germany and a MODX Ambassador. I am also co-founder of SEDA.digital, a MODX Agency.
            • Ok, my script appeared to be working at first. But upon further review, when you open the second page it shows the first resulting entries. The entry list is not offset by the limit parameter. Not sure how to solve that yet.
                Benjamin Davis: American web designer living in Munich, Germany and a MODX Ambassador. I am also co-founder of SEDA.digital, a MODX Agency.
                • 4172
                • 5,888 Posts
                this is working for me. Have you called your snippet uncached?
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 44234
                  • 219 Posts
                  You may find the Extra below useful. Docs include code examples of how to use it with getResources to filter by date/timestamp. Happy to assist if you have any questions.

                  getDate Extra:
                  http://modx.com/extras/package/getdate

                  Docs & Usage Examples:
                  http://rtfm.modx.com/extras/revo/getdate#getDate-getResourcesExamples
                    Find me on Twitter, GitHub or Google+