We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8822
    • 203 Posts
    Hi, does anyone know if it is possible to sort by multiple TVs using getResources? I am currently using getPage and getResources to generate a list of businesses and it is currently sorting by the TV 'starrating'. I would like it to sort by this TV first and then sort by another TV. Is this possible? The code i am using is below.

    [[!getPage?
       &elementClass=`modSnippet`
       &element=`getResources`
     
       &parents=`3`
       &depth=`2`
       &limit=`10`
       &pageVarKey=`page`
     
       &includeTVs=`1`
       &includeContent=`1`
     
       &tpl=`catlisttpl`
       &where=`{"template:IN":[4]}` &tvFilters=`categories==[[*categories]]` &sortbyTV=`starrating` &sortdirTV=`DESC`
    ]]
      • 22303 MODX Staff
      • 10,725 Posts
      That is not possible with getResources. And to be honest, unless you have a very limited dataset, I would not recommend doing this. Template Variables are exactly what they say they are, ways to vary a Template. They are not intended for searching, sorting, and/or filtering data, and as such, are very inefficient at that task. This becomes more obvious as you attempt to scale up your dataset.

      That said, if you put in a feature request at https://github.com/opengeek/getResources/issues I can look into implementing this for those who have limited datasets.
        • 8822
        • 203 Posts
        Thanks opengeek, any recommendations on what the best way of implementing this would be. I have a list of businesses, each as a separate resource and then a summary list of all businesses for a given category. This list needs to be ordered by their ratings, recommendations and type of listing they have - all of which i currently have as template variables.

        Many thanks for your help
          • 42046
          • 436 Posts
          I haven't tried is personally but pdoResources in pdoTool http://modx.com/extras/package/pdotools allows you to use a JSON array in &sortby, including TVs.

          &sortby
          default: publishedon
          type: textfield
          Description: Any resource field for sorting, including the TV option if it is specified in the parameter "includeTVs". You can specify an array of JSON string with several fields. To randomly select sorting "RAND ()"
            • 28120
            • 380 Posts
            Quote from: opengeek at Sep 24, 2013, 08:26 AM
            Template Variables are exactly what they say they are, ways to vary a Template.

            Interesting point that.

            Do most developers use TV's as ways to vary a template or do they use them as extended fields. Maybe ask for a show of hands at MODXpo.