We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11139
    • 34 Posts
    I want to filter by age less than X, greater than X, etc.

    This works: &tvFilters=`age==3`

    But versions like &tvFilters=`age>3` don’t work - nothing else that I’ve tried will work.

    Anybody know the answer?

      • 22303 MODX Staff
      • 10,725 Posts
      That is not supported by the getResources component.
        • 11139
        • 34 Posts
        OK, thanks.

        Should I use Ditto for filtering?

          • 11139
          • 34 Posts
          (I should have made clear that this topic addresses Revo.) I’ve found one answer, so if anyone else needs to know, here it is. May be others of course. You filter the results in the chunk, rather than adding conditions to the getResources call. Here’s how.

          1) Make your getResources send its findings to a chunk. I’ve called mine ifList:

          [[ !getResources? &parents=`8`
          &tpl=`ifList`
          &includeTVs=`1`
          ]]


          2) Do the filtering in the chunk, using the If snippet:


          [[!If?
          &subject=`[[+tv.age]]`
          &operator=`GT`
          &operand=`3`
          &then=`yes [[+tv.age]]`
          &else=`no [[+tv.age]]`
          ]]

          You will have to download and install the If snippet. It comes with rather thin documentation, so you will have to guess what operators are available sad
            • 22303 MODX Staff
            • 10,725 Posts
            You can do that, but you are still processing every Resource. That could get very inefficient if not cached properly.
              • 11139
              • 34 Posts
              Please can you guide me towards an alternative?

              I’m very much feeling my way through all this. Help very much appreciated.