We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30505
    • 5 Posts
    I have not been able to figure out how to use getResources to output a list of future events (pages). The events have a date-type template variable called "pubDate" that I am using to sort the list. I’d like to be able to create two separate lists...one for current/future events and one for past events. I have created a snippet for the event listing but this currently displays everything:

    <?php
    $docInfo = $modx->getDocument($modx->documentIdentifier,'id');
    $page_id = $docInfo['id'];
    
    if ( $page_id == 67 ) {
    	echo "<ul class=\"news\">";
    	$sfOutput = $modx->runSnippet(
    		"getPage",
    		array(
    			"elementClass" => "modSnippet",
    			"element" => "getResources",
    			"parents" => "67",
    			"depth" => "1",
    			"limit" => "10",
    			"pageVarKey" => "page",
    			"sortbyTV" => "pubDate", 
    			"sortbyTVType" => "datetime",
    			"includeTVs" => "1",
    			"processTVs" => "1",
    			"tpl" => "pubRow_events"
    		)
    	);
    
    	echo $sfOutput;
    	echo "</ul>";
    
    	echo "<div class=\"paging\">";
    	echo "<ul class=\"pageList\">";
    	echo "[[!+page.nav]]";
    	echo "</ul>";
    	echo "</div>";
    }
    


    I know from perusing the forum posts that the where clause does not work with TVs. Is there some other way to do this? I would consider using the "publishedon" field as a fallback option if the TV field cannot be used. Any help would be greatly appreciated.

    Thanks,
    Tom
      • 3749
      • 24,544 Posts
      How about just setting the Published On date (pub_date field in the tag)?

      You could have one getResources call show published documents, sorted by publishedon, and another show unpublished documents, sorted by pub_date.
        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
        • 30505
        • 5 Posts
        Quote from: BobRay at Apr 26, 2011, 03:22 AM

        How about just setting the Published On date (pub_date field in the tag)?

        You could have one getResources call show published documents, sorted by publishedon, and another show unpublished documents, sorted by pub_date.

        This solution sounded promising and I gave it a try, but I ran into two problems. 1) When an unpub_date is set and the date comes past, the publishedon date gets cleared. I’m trying to build a page that shows past events but when the publishedon date gets cleared, the past events lose context and a field to sort on. 2) I have not been able to return a list of only past events. I can show a list of current and past events by adding the "&showUnpublished=`1`" parameter. I’ve been trying to use a where parameter: "&where=`[{"unpub_date:<=":"[[today]]"}]`)" where the today snippet returns today’s date:

        <?php
        if(!isset($ts)) { 
                  $ts=time(); 
             } 
             return $ts;


        With these settings, the getResources snippet returns an empty set. It’s quite possible that I’m not using the where parameter correctly, but I’ve not been able to get this working in any way.

        Using a TV date field works for the most part if I could only figure out how to return only past events based on the unpub_date. Any suggestions?
          • 3749
          • 24,544 Posts
          Your code looks good to me, but I think pub_date is zeroed out on publication and unpub_date is zeroed out on unpublication (not sure about this).

          One option might be to delete the past events but not purge them. Then you could use the &showDeleted property and select resources where deleted=1.



            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
            • 34911
            • 1 Posts
            I am also trying to do the same thing. Have you found any solution here? Please share
              • 35302
              • 7 Posts
              "&where=`[{"unpub_date:<=":"[[today]]"}]`)"


              I did the same thing and I got it working where the past events are filtering out. This part of your code is different than mine.

              I think it’s supposed to be &where=`{"unpub_date:<=":[[today]]}`. Not sure if that’s going to do it, but it’s what made mine work.

              Also I found it helps if you have one chunk (or snippet if that’s what you want to use) for current events and another for past events, and on past events you put the &showUnpublished and &where. Then just call both in the page you want them to display.

              Hope that helps.
              • @krock This is just what I'm looking for but I've tried your &where code and can't get it to work - what am I missing?

                  [[getResources? &tpl=`monthlyCalendar` &sortby=`unpub_date` &where=`{"unpub_date:<=":}` &showUnpublished=`1`  &sortdir=`asc` &includeContent=`1` &includeTVs=`1` &processTVs=`1` &showHidden=`1` &limit=`12` ]]    
                


                Could you post your solution. Many thanks
                  Helen Warner
                  Number one pixel!
                  Proud to be linked with MODX at Crimson Pixel
                  • 6902
                  • 126 Posts
                  I had to come up with a solution for doing events as well using TVs for the date field. I really didn't want to use publish and unpublish as that is really not what those fields are for. Anyway, after wracking my brain a bit, the solution ended up being fairly simple:

                  First, create a small snippet (I called mine curDate) to return the current datetime string:

                  <?php
                  return date('Y-m-d H:i:s');


                  Then you can use the getResources tvFilters using this snippet:

                  Current events:
                  [[!getResources?
                    ...
                    &tvFilters=`myDateTV>=[[curDate]]`
                  ]]


                  Past events:
                  [[!getResources?
                    ...
                    &tvFilters=`myDateTV<<[[curDate]]`
                  ]]