MODX Community

pdoResource WHERE

Hello!
I create a megamenu, soI try to separate resources based on the column they must appear.
I have a TV, listbox (single select), with default to 1 and values from 1 to 6.

So, I need, first to get all resources for each column.
Please, tell me if something is wrong here, because I tried almost everything and nothing!

                    [[!pdoResources?
                        &parents=`[[+id]]`
                        &depth=`0`
                        &tpl=`Level1MM`
                        &prepareTVs=`1`
                        &processTVs=`1`
                        &includeTVs=`mmColoana`
                        &where=`{"mmColoana:=":"1"}`
                        &sortby=`{ "parent":"ASC", "menuindex":"ASC" }`
                    ]]

P.S. When I remove the where clause, everything is shown.

Thank you!

1 Like

Try adding this (assuming that your TV does not have the tv. prefix):

&tvPrefix=``
1 Like

Thank you!
I’ll try.
In the mean time, I resolved the issue with:
&tvFilters=mmColoana==1

And, also, I read a post with somehow similar problem, caused by the default TV value, which is not written in the MySQL table.

So, now I need to figure out a way to write something like this, to include the default value, 1:
&tvFilters=mmColoana==1||mmColoana =="" or something with NULL. I had no time to test…

So, maybe in the WHERE clause, it is about tvPrefix, but, in the main logic, I think the default TV value is the real problem.

Anyway, very poor documentation for such a good tool like pdoTools. I can’t figure out clear when I need statements like &tvPrefix, prepareTVs, processTVs and, for example, why I need an extra tvFilters when I have the Where clause.

Also very few working examples…

I know getResources will still work when the TV is set to its default value and there’s no record in the table. I’m not sure if pdoResources does or not.

I usually set a default value like ‘…’ or just a blank for TVs, so that no resource will actually have that value for the TV. It make things a lot faster if there’s a record for every TV in the table. Be careful if you choose to go that route at this point, because you’ll have to reset the TV values for the resources that have the default value and then re-save those resources (or use a utility snippet to make the corrections).

1 Like