getResources tvFilters query delimiter grouping


I am trying to get a getResources query using tvFilters to work as part of a legacy codebase (hence why I am pursuing this way of doing things rather than using an alternative implementation.

The tvFilter which previously worked was of the form below where some resources are being filtered based on their template variables.

The issue arises when trying to modify this to deal with a set of alternative address queries to filter as below.


I have discovered, however, that getResources uses the OR operator as the primary delimiter and does not allow for any kind of grouping such as with brackets so whilst the behaviour I am looking for is like the first pseudo query below, I appear to be getting the second query.

    • (address==%lorem%||address==%ipsum%||address==%dolor%),entrances<=2,costFactor>=100
    • address==%lorem%||address==%ipsum%||(address==%dolor%,entrances<=2,costFactor>=100)

In other words, what I am trying to achieve is filtering for properties where the costFactor is greater than or equal to 100, entrances is less than or equal to two and the address contains either lorem, ipsum or dolor. As I understand it (I stand to be corrected) it is not possible to achieve this with how tvFilters are parsed.

Now obviously, one answer to this question is to use something else, however I was keen to see if I could make getResources work because of its heavy use already. Having had a look at the code for getResources, it seemed that it might be possible to simply reverse the use of OR and AND to change the parsing order. Having done this the code seems to work however since this was more of a blind cut and past than a principled change with understanding of the underlying queries, I wonder if anyone can see any problems with the code I have produced (beyond the confusion of having a modified version of a standard snippet)

Here is a link showing the changes I have made as well as a standalone link to the new version of the code

If anyone was able to comment on this or set straight any problems with my understanding of the situation that would be very much appreciated.


Are you sure that all TVs have a value that is not the default for that TV and, that the raw values stored in the modx_site_tmplvar_contentvalues table matche your criteria?

Have you tried grouping them with parentheses?