We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29467
    • 2 Posts
    I’ve been googling up and down for two hours now *grins* so it’s time to ask for some help that I’ve not been able to find an answer to.

    I have a date TV that holds an event’s start date. I want to filter out any documents where the date TV (EventStartDate) is older than the current date, so that I can display all the future events, and later do the reverse to list past events.

    The EventStartDate TV is using the Unix timestamp widget and the sorting is working fine.

    Here’s the Ditto call at present.

    [!Ditto? &filter=`EventStartDate,3,@EVAL return time();` &tpl=`Events` &sortBy=`EventStartDate` &sortDir=`ASC` !]


    Nothing is being filtered at all, whether or not it is greater or lesser than todays date.

    So what’s up with my filter? I keep reading about a "Debug Console" but haven’t worked out how to open it?

    I’ve probably done something rather stupid so forgive me if that’s the case, I’ve just started using ModX today to see if it will work for the client’s needs.

    Ta in advance.
      • 25663 MODX Staff
      • 12,272 Posts
      Debug console: &debug=`1`

      I think you have your order wrong in the filter according to: http://ditto.modxcms.com/tutorials/basic_filtering.html. Seems that it should be: &filter=`EventStartDate,@EVAL return time(),3`.
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 29467
        • 2 Posts
        See, I knew I was being stupid!

        Thanks.

        *goes and fixes it*

        Yup..

        &filter=`EventStartDate,@EVAL return time();,3`


        ..works great. ( once I added the semicolon smiley )

        Thank you. Duh, I couldn’t see the wood for the trees, should go to sleep really. Gotta get up in 4 hours! *giggles*

        Thanks again, and subject changed to [Solved]
          • 32645
          • 377 Posts
          What is the reverse of:

          &filter=`EventStartDate,@EVAL return time(),3`.

          So that you get only articles from the past?

          Any help on this would be welcome.
            • 10449
            • 956 Posts
            See the comparison mode table? http://ditto.modxcms.com/tutorials/basic_filtering.html
            I guess you’ll want to use 4 or 6 instead of 3.
              • 7231
              • 4,205 Posts
              I am trying to filter only documents that were published on a given date. However when I apply my filter it will only return exact matches for that time stamp rather than for the full day. My filter is &filter=`pub_date,@EVAL time();,2` If I format the date using strftime to get a day it will not return anything since pub_date does not match anything (different formats). Is it possible to format the pub_date to use int he filter?
                [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                Something is happening here, but you don't know what it is.
                Do you, Mr. Jones? - [bob dylan]
                • 4172
                • 5,888 Posts
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 7231
                  • 4,205 Posts
                  Bruno17: thanks, I forgot about the date filter extension (for some reason I thought it was only for Reflect). Lookis like I will need to do some trial and error before I figure it out and get it to do what I want.

                  Anyway, I used a standard query to get todays document’s ID and use the ID in the Ditto call to get the document data. This may be more efficient since it does no filtering and is a simple query.

                  If anyone is interested here is the final snippet, it does a query to get today’s document that is published, if no docs are published it loads a default:
                  <?php
                  // examle call [!TodayDoc? &parent=`792` &default=`793`!]
                  
                  // id of parent container document
                  $parent = isset($parent) ? $parent : "0";
                  
                  // set the default document can be added to the call
                  $default = isset($default) ? $default : "1";
                  
                  //Step 1 - query to find post to be published today
                  $table = $modx->getFullTableName("site_content");
                  $fields = "id";
                  $where = "(FROM_UNIXTIME( pub_date, '%Y-%m-%d' ) = CURDATE( )) AND (parent = ".$parent.") AND (published = '1')";
                  $rs = $modx->db->select("id",$table,$where,"pub_date DESC","1");
                  if($modx->db->getRecordCount($rs) >= 1) {
                  	$row = $modx->db->getRow($rs);
                  	$today_doc = $row['id'];
                  } else {
                  	$today_doc = $default;
                  }
                  
                  // Step 2 - get documet with ditto
                  $output = $modx->runSnippet("Ditto", array(
                  	"documents" => $today_doc,
                  	"display" => $display,
                  	"tpl" => "yourTplHere" ));
                  
                  // Step 3 -  output the results
                  return $output;
                  
                  ?>

                    [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                    Something is happening here, but you don&#39;t know what it is.
                    Do you, Mr. Jones? - [bob dylan]
                    • 10313
                    • 375 Posts
                    Quote from: ganeshXL at Dec 14, 2007, 07:50 AM

                    See the comparison mode table? http://ditto.modxcms.com/tutorials/basic_filtering.html
                    I guess you’ll want to use 4 or 6 instead of 3.
                    This was the answer for the question how to get the reverse of using "3" as filter mode.

                    I’m still havin problems. Got a date TV dateVon as Unixetime. If I use
                    &filter=`datumVon,@EVAL return time();,6`

                    I expect to get all docs where the given Date is in the past (filter out all future dates).

                    Vice versa, I expect to get all docs where the given Date is in the future, if I use
                    &filter=`datumVon,@EVAL return time();,3`


                    But: I get the future docs in both cases. This cant be right. Even if I still have an error in my thoughts or TV, I should not get the same empty result when I use opposite comparison mode, should I?

                    If I use "2" (equal), I get all docs (which is correct). I have never ever got running this filtering by date.

                    PLEASE, I need you help huh
                    Thanks
                    Martin
                      • 4172
                      • 5,888 Posts
                      seems ok to me and should work, what is the output when you have [*datumVon*] in your Template or Document-content?
                      can you also show your complete Ditto-call here?
                        -------------------------------

                        you can buy me a beer, if you like MIGX

                        http://webcmsolutions.de/migx.html

                        Thanks!