We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • If you are using the latest official version of getResources it is sortbyTV (there is a hacked version in this thread with different parameters that are lowercase), and your call is wrong. It should look like this:

    [[!getResources? &parents=`2` &tpl=`events-page.tpl` &depth=`0` &includeTVs=`1` &processTVs=`1` &hideContainers=`1` &limit=`0` &sortbyTV=`start-date` &sortdirTV=`ASC` &tvFilters=`archived==YES` ]]


    Notice the value of sortbyTV is the name of the TV, not the placeholder tag used for outputting TV content in the tpl’s.
      • 886
      • 39 Posts
      oups, I didn’t realize it was a different version here..

      Anyway, I already mentioned I tried using
      sortbyTV=`start-date`
      and it works the same way. Every resource is returned multiple times. Also tried using
      sortby=``
      to see if that would have anything to do, but nothing changed.
      Quote from: alejaaandro at Oct 16, 2010, 08:22 PM

      I’ve also tried
      sortbytv**=`start-date` works as the above
      sortbytv=`[[+tv.start-date:strtotime]]`  does not work (defaults to sortby=publishedon


      **i meant sortbyTV, i just misspelled it previously in the forum..
      • Quote from: alejaaandro at Oct 16, 2010, 10:51 PM

        Anyway, I already mentioned I tried using
        sortbyTV=`start-date`
        and it works the same way. Every resource is returned multiple times. Also tried using
        sortby=``
        to see if that would have anything to do, but nothing changed.
        Sorry, didn’t read all the way back; this appears to be a bug in the new feature and has been reported in another thread. Would you mind entering a bug report for this at http://github.com/opengeek/getResources/issues and I’ll see if I can debug/solve it today.
          • 886
          • 39 Posts
          • Quote from: alejaaandro at Oct 19, 2010, 12:02 AM

            bug report has been created

            http://github.com/opengeek/getResources/issues#issue/19
            Thank you sir.

            And issue 19 has been fixed in 1.2.2-pl, available now in your Package Management Interface.
              • 886
              • 39 Posts
              Seems to work fine..

              Thanks for fixing it so quickly smiley
                • 25141
                • 49 Posts
                Hi,

                almost got this working after the update - just seems to me that &sortdirTV=`ASC` won’t output anything. &sortdirTV=`DESC` at least outputs something, if not the order I was looking for.

                Somebody know what the issue could be?

                - R
                  • 11681
                  • 98 Posts
                  Hello,

                  I have also run into difficulty sorting by a date template variable.

                  Before reading any further, please advise if this has been solved on another thread or in docs. I could find only this thread as apropos.

                  I'm in the midst of porting an Evo 1.0.5 site to Revo 2.1.2-pl (using version 2.1.2-pl because the Provisioner documentation says that Provisioner is not supported in later Revo versions). The Evo site successfully uses this Ditto snippet call:
                  [!Ditto?
                    &id=`homeEvents`
                    &debug=`0`
                    &parents=`6`
                    &display=`1`
                    &total=`1`
                    &showPublishedOnly=`0`
                    &orderBy=`myDate ASC`
                    &filter=`myDate,@EVAL return strtotime('0 hour');,3`
                    &dateSource=`createdon`
                    &dateFormat=`%c`
                    &tpl=`homeMainEventsTpl`
                  !]

                  Note that strtotime() in the filter parameter is reflective of variable 'myDate' being of type unixtime.

                  Out of a collection of documents with various 'myDate' values, the above call gets the document whose 'myDate' says it is the Event that is next going to happen.

                  The closest I've been able to get to achieving the same thing in Revo is the following call (made in the page template, with the TV default value blank):
                  [[!getResources?
                    &parents=`6`
                    &depth=`1`
                    &showHidden=`1`
                    &showUnpublished=`1`
                    &includeContent=`1`
                    &tvPrefix=``
                    &includeTVs=`1`
                    &processTVs=`1`
                    &sortbyTV=`myDate`
                    &sortdirTV=`ASC`
                    &sortbyTVType=`string`
                    &limit=`1`
                  ]]

                  The above call gets not the next-to-happen Event resource but instead the oldest one according to 'myDate'. It's as though the TV sort direction (ASC) is ignored in favor of the default (DESC). The call produces this dump:
                  Array
                  (
                      [tpl] => 
                      [tplOdd] => 
                      [tplFirst] => 
                      [tplLast] => 
                      [sortby] => publishedon
                      [sortbyTV] => myDate
                      [sortbyTVType] => string
                      [sortbyAlias] => 
                      [sortbyEscaped] => 0
                      [sortdir] => DESC
                      [sortdirTV] => ASC
                      [limit] => 1
                      [offset] => 0
                      [tvFilters] => 
                      [depth] => 1
                      [parents] => 6
                      [includeContent] => 1
                      [includeTVs] => 1
                      [includeTVList] => 
                      [showHidden] => 1
                      [showUnpublished] => 1
                      [showDeleted] => 
                      [resources] => 
                      [processTVs] => 1
                      [processTVList] => 
                      [tvPrefix] => 
                      [idx] => 1
                      [first] => 1
                      [last] => 1
                      [toPlaceholder] => 
                      [toSeparatePlaceholders] => 
                      [debug] => 
                      [where] => 
                      [dbCacheFlag] => 0
                      [context] => 
                      [id] => 232
                      [type] => document
                      [contentType] => text/html
                      [pagetitle] => Event - Politics and Cocktails
                      [longtitle] => Celebrate Scott Brown's Victory at Our Post-Election Party
                      [description] => 
                      [alias] => event-politics-and-cocktails1
                      [link_attributes] => 
                      [published] => 
                      [pub_date] => 0
                      [unpub_date] => 0
                      [parent] => 6
                      [isfolder] => 
                      [introtext] => 
                      [content] => 
                  7:00 PM, Tuesday, February 2
                  Gibbet Hill Grill
                  57 Lowell Road (Rt. 40), Groton
                  
                  Join Us for a Fun, Social Evening!
                  
                      [richtext] => 1
                      [template] => 6
                      [menuindex] => 0
                      [searchable] => 1
                      [cacheable] => 1
                      [createdby] => 1
                      [createdon] => 2010-03-19 03:02:16
                      [editedby] => 1
                      [editedon] => 2010-09-23 02:55:37
                      [deleted] => 
                      [deletedon] => 0
                      [deletedby] => 0
                      [publishedon] => 0
                      [publishedby] => 0
                      [menutitle] => 
                      [donthit] => 
                      [privateweb] => 
                      [privatemgr] => 
                      [content_dispo] => 0
                      [hidemenu] => 
                      [class_key] => modDocument
                      [context_key] => web
                      [content_type] => 1
                      [uri] => event-politics-and-cocktails1.html
                      [uri_override] => 0
                      [sortTV] => 02/2/2010 19:00
                      [myDate] => 2010-02-02 19:00:00
                  )

                  Maybe more than one problem is happening here. Maybe the cure includes both getting the sort direction set as intended AND picking appropriate input and/or output transformation(s) of the TV. In particular, I was not able to figure out the string date vs. unixtime issue.

                  BTW, this similar call, which uses the 'createdon' resource attribute to get the latest News resource, works just fine:
                  [[!getResources?
                    &parents=`5`
                    &depth=`1`
                    &showHidden=`1`
                    &showUnpublished=`1`
                    &includeContent=`1`
                    &sortby=`{"createdon":"DESC"}`
                    &limit=`1`
                    &tpl=`homeMainNewsTpl`
                  ]]

                  I have spent hours methodically trying variations and am stumped. Expert advice eagerly solicited! [ed. note: halfnium last edited this post 11 years, 8 months ago.]
                    I looked just like that in 1964.
                    • 11681
                    • 98 Posts
                    After numerous attempts over the last 9 months, I've finallly gotten getResources selection, sorting and filtering according to a date template variable to work. Thought I would save other MODX users time & trouble by writing about it.

                    First, why sort on date? Well, because presentations such as calendars and lists of events are naturally date-ordered. I almost gave up on sorting by date TV, since the built-in unpub_date resource field offers semantically ALMOST the same thing: It's usually fine to unpublish a notice once an event is underway. Sorting by a resource field in getResources is straightforward. Sorting by TV involves fiddling with several substitute or additional getResources properties and options. Failure to provide getResources with exactly what it needs / wants results in puzzling output, without error messages or other hints.

                    So, if you can get by without sorting on a date TV, I recommend you do that.

                    However, "semantically almost the same" isn't always enough. The date upon which some event is to commence is not quite the same as the date upon which to stop publicizing it. How about events that run across multiple days, for example?

                    Besides, I had already entered TV dates for over 1000 events logged into a MODX Evolution site over the previous two years. I was in the midst of porting this site over to Revolution, replacing ditto with getResources. This was a technology refresh, so I didn't want to go backward. And most certainly I didn't relish the prospect of cutting & pasting dates from the TV tab into the Settings tab for 1000+ resources!

                    So I updated getResources to the latest version (1.5.0-pl) on my development version of Revolution (2.2.0-pl2) and carefully followed the document at http://rtfm.modx.com/display/ADDON/getResources. I temporarily deleted the 'tpl' property reference in order to view the getResources dump.

                    I encountered bizarre results. After many experiments, I learned that a defective getResources call returns the first N resources ascending-ordered by ID number, where N is specified by the getResources 'limit' property. I also noted that a seemingly correct getResources call sorting on my date TV would return an unexpected set of resources, and these not even presented in correct date order! However, the call delivered the same results repeatably, and cache-clearing on host and client made no difference.

                    What to do?

                    About to lose hope, I had a breakthrough. By instrumenting the template to which my event date TV was attached, I noticed that the TV date instances were not of uniform format. It was a mixed bag:


                    • YYYY-mm-dd HH:MM:SS (24-hour time format)
                      Example: 2010-06-04 15:30:23

                    • Month-spelled-out day-with-leading-zero-suppressed, YYYY h:m AM||PM
                      Example: June 4, 2010 3:30 PM

                    • M-with-leading-zero-suppressed/D-with-leading-zero-suppressed/YYYY h:m AM||PM
                      Example: 6/4/2010 3:30 PM

                    • M-with-leading-zero-suppressed/D-with-leading-zero-suppressed/YY h:m AM||PM
                      Example: 6/4/10 3:30 PM

                    I confirmed this by checking the database using phpMyAdmin.

                    What a mess! I don't know where all of those format variations came from. I must have caused them by monkeying around with the date TV's Input and Output Options.

                    Apparently, ditto on Evo had no problem with the format mish mash, but GetResources on Revo doesn't like it. getResources apparently REQUIRES the first of the above four formats, which I suppose is what "&sortbyTVType= `datetime`" is all about. Of course! It's unreasonable to expect sorting to work on arbitrary date formats, and that first format is so easy and efficient to sort.

                    Meanwhile, the built-in resource fields, such as the 'createdon' date, are also formatted in the first way given above.

                    A big clue came in jrotering's forum post, http://forums.modx.com/?action=thread&thread=74320. His sole error was getting the capitalization of a getResources property wrong. Once he fixed that, he (rather amusingly) revealed that his call worked properly! Note that he carefully explained how his date TV instances were formatted.

                    This encouraged me to regularize my date TV instances. It wasn't so bad a chore. Database table 'modx_site_tmplvar_contentvalues' contains all of the date TV instances. I used phpMyAdmin to examine and edit the incorrectly formatted ones.

                    The date instances having been fixed, I'm happy to report that the following getResources call selects and sorts as desired on date TV:

                    [[!getResources?
                      &parents= `6`
                      &depth= `1`
                      &showUnpublished= `1`
                      &showDeleted= `0`
                      &includeContent= `1`
                      &tvPrefix= ``
                      &includeTVs= `1`
                      &processTVs= `1`
                      &processTVList= `eventDate`
                      &sortbyTVType= `datetime`
                      &sortbyTV= `eventDate`
                      &sortdirTV= `DESC`
                      &limit= `5`
                      &tpl= `homeMainEventsTpl`
                    ]]
                    

                    So, if you're having trouble using getResources with a date TV, work your way through this checklist:



                    • Remove the 'tpl' property in order to enable the properties & options dump.

                    • Ensure that you're using the back-tilted single quotes in the snippet call. I Don't mean to insult anyone's intelligence. Failing to do that is a frequent error of mine.

                    • Ensure that spellings and capitalizations of property names are correct.

                    • Ensure the same for template variables.

                    • Using phpMyAdmin, check TV dates in the database and ensure all are of the form discussed above.

                    • To avoid future format problems, ensure that the Input Options for the date TV upon which you intend to sort is specified as

                      'Input Type: Date'
                      'Allow Blank: No'

                      and the Output Options as

                      'Output Type: Date'
                      'Date Format: %Y-%m-%d %H:%M:%S'

                    Next problem: Restricting resources to dates in the past or in the future. There is no point showing past events to users hoping to plan ahead. Likewise, there is no point in showing future events to users whose interest is historical.

                    A gentleman writing under the agreeably musical name debussy suggests (http://forums.modx.com/thread/43727/getresources-to-show-current-and-future-events#dis-post-419669) using a custom snippet, which I have named "currentDatetime."
                    <?php
                    return date('Y-m-d H:i:s');
                    ?>

                    Use this snippet as part of yet another getResources property, "&tvFilters." This version of the property restricts getResources to reporting on the future:
                      &tvFilters= `eventDate>>[[!currentDatetime]]`

                    and this version restricts getResources to reporting on the past:
                      &tvFilters= `eventDate<<[[!currentDatetime]]`

                    =====================

                    I hope that the MODX folks add date-TV selection, sorting and filtering to http://rtfm.modx.com/display/ADDON/getResources.Examples, and that Bob Ray covers it in the next edition of his excellent book. [ed. note: halfnium last edited this post 10 years, 9 months ago.]
                      I looked just like that in 1964.
                      • 42377
                      • 14 Posts
                      Is there a way to link the output back to the TV's resource? I'm creating a company directory, filtering and displaying the TV's from each employee's (attorneys) bio page resource, but I also want the name of the attorney to link back to each his/her own bio page (where the TV data came from to begin with). I tried linking to parent but it doesn't work.

                      I have the following:

                      directory-thumb chunk:
                      [[!getResources?&parents=`66` &tvFilters=`topposition==attorney` &limit=`100`&includeTVs=`1`&includeContent=`1` &sortbyTV=`lastname` &sortdirTV=`ASC` &tpl=`directory-tpl`]]


                      directory-tpl chunk:
                        <tr>
                          <td bgcolor="#F4F5F7"><a href="[[*parent]]">[[+tv.FirstName]] [[+tv.LastName]]</a></td>
                          <td bgcolor="#F4F5F7">[[+tv.Position]]</td>
                          <td bgcolor="#F4F5F7">[[+tv.PracticeAreas]]</td>
                          <td bgcolor="#F4F5F7">[[+tv.Locations]]</td>
                          <td bgcolor="#F4F5F7">[[+tv.Phone]]</td>
                          <td bgcolor="#F4F5F7"><a href="mailto:[[+tv.Email]]"><img src="assets/img/email_icon.gif"></a></td>
                        </tr>



                      I am using Revo 2.2.6

                      Thanks a million.
                      -Jamie [ed. note: jamesb last edited this post 11 years, 3 months ago.]