MODX Community

pdoResources filters

Hi,

I’m trying to sort some pdoressources result with tv value
my tv is an radio button (oui||non)
i have tryed this one but i get nothing

            [[pdoResources?
                &parents=`12`
                &includeContent=`1`
                &limit=`[[*StartupTileNbrTV]]`
                &includeTVs=`SelectedStartupTV,HeaderImageTV,StartupPercentDoneTV,OldStartupTV`
                &tpl=`StartupTilesTpl`
                &sortby=`menuindex`
                &sortdirTV=`DESC`
                &where=`{"SelectedStartupTV:=":"non"}`
            ]]

nor with those

&where=`{"OldStartupTV.value":"non"}`

or

&tvFilters=`OldStartupTV==non`

strange because this code is working:

                [[pdoResources?
                &parents=`12`
                &includeContent=`1`
                &limit=`[[*StartupTileNbrTV]]`
                &includeTVs=`SelectedStartupTV,HeaderImageTV,StartupPercentDoneTV`
                &tpl=`SelectedStartupTpl`
                &where=`{"SelectedStartupTV:=":"oui"}`
                &sortby=`menuindex`
                &sortdirTV=`DESC`]]

i found this tread interesting but i cant manage to make it work for me
https://forums.modx.com/thread/92071/pdoresources-and-tvfilters

i search for &where and &tvfilter exemple with operator but can’t get something relevant

Maybe you’re JSON is wrong, try: &where= {"SelectedStartupTV":"oui"}. Also, check if you set the radio naming correctly. It can also be that SelectedStartupTV’s value is not “oui” but “on”.

Thanks for your reply.

i use pdofield to get the value of TV :

[[pdofield? &id=`41` &field=`OldStartupTV`]]
[[pdofield? &id=`22` &field=`OldStartupTV`]]

those two ressources have different content value for tv button and i get “oui” and “non” (french yes and no) in result

i am really confused because i then test this code

            [[pdoResources?
                &parents=`12`
                &includeContent=`1`
                &limit=`[[*StartupTileNbrTV]]`
                &includeTVs=`SelectedStartupTV,HeaderImageTV,StartupPercentDoneTV,OldStartupTV`
                &tpl=`StartupTilesTpl`
                &sortby=`menuindex`
                &sortdirTV=`DESC`
                &where=`{"OldStartupTV":"non"}`
            ]]

and it return an empty result
and when i test this one :

            [[pdoResources?
                &parents=`12`
                &includeContent=`1`
                &limit=`[[*StartupTileNbrTV]]`
                &includeTVs=`SelectedStartupTV,HeaderImageTV,StartupPercentDoneTV,OldStartupTV`
                &tpl=`StartupTilesTpl`
                &sortby=`menuindex`
                &sortdirTV=`DESC`
                &where=`{"OldStartupTV":"oui"}`
            ]]

i got good result …
it’s weird !!!

Give this a try:

where=`{"OldStartupTV":"1"}

Yes/No TVs are stored as 0 and 1 in the DB, and PdoResources may be using the raw values.

i try it and i got all the ressources without sorting.
i try this one to try to process the result of raw value

&processTVs=`1` 

but it doesn’t work either

I get this one working with getRessources

                [[getResources?
                    &parents=`12`
                    &includeContent=`1`
                    &limit=`[[*StartupTileNbrTV]]`
                    &includeTVs=`1`
                    &tpl=`StartupTilesTpl`
                    &sortby=`menuindex`
                    &sortdir=`DESC`
                    &processTVs=`1`
                    &tvFilters=`OldStartupTV==non`
                ]]

I notice that in all cases you are calling the snippets uncached.

[[pdoResources?

or

[[getResources?

If you call them uncached do you get the results you expect?

[[!pdoResources?

or

[[!getResources?

thanks,
I try to uncache pdoressources,

                    [[!pdoResources?
                    &parents=`5`
                    &includeContent=`1`
                    &limit=`[[*StartupTileNbrTV]]`
                    &includeTVs=`SelectedStartupTV,HeaderImageTV,StartupPercentDoneTV,OldStartupTV`
                    &tpl=`StartupTilesTpl`
                    &sortby=`menuindex`
                    &sortdirTV=`DESC`
                    &processTVs=`1`
                    &where=`{"OldStartupTV":"1"}`
                    ]]

but i got nothing : no code was generated
(i changed ressource folder but it’s just for tree cleaning)

in those case i got something

                    [[pdoResources?
                    &parents=`5`
                    &includeContent=`1`
                    &limit=`[[*StartupTileNbrTV]]`
                    &includeTVs=`SelectedStartupTV,HeaderImageTV,StartupPercentDoneTV,OldStartupTV`
                    &tpl=`StartupTilesTpl`
                    &sortby=`menuindex`
                    &sortdirTV=`DESC`
                    &processTVs=`1`
                    &where=`{"OldStartupTV:>":"non"}`
                    ]]
                    [[pdoResources?
                    &parents=`5`
                    &includeContent=`1`
                    &limit=`[[*StartupTileNbrTV]]`
                    &includeTVs=`SelectedStartupTV,HeaderImageTV,StartupPercentDoneTV,OldStartupTV`
                    &tpl=`StartupTilesTpl`
                    &sortby=`menuindex`
                    &sortdirTV=`DESC`
                    &processTVs=`1`
                    &where=`{"OldStartupTV:=":"oui"}`
                    ]]

with those one i got ressources selected, but the one i dont want
with

&where=`{"OldStartupTV:>":"oui"}`

or

&where=`{"OldStartupTV:=":"non"}`

i got nothing …

Here’s something else to try:

&where=`{"OldStartupTV.value:=":"oui"}`

Also, an old post suggested that pdoResources doesn’t handle TVs set to their default value properly. I don’t know if this is still true, but if it is, and the TV has a default value of ‘oui’ or ‘non’ that could be your problem.

The underlying reason is that TVs set to their default value have no record in the table that holds the TV values for specific resources, which is where pdoResources looks (or used to look) for the values.

One solution would be to switch to getResources and use its &tvFilters property.

i understand the tricks with default value, it’s one of the first thing i do: go to every ressource change value and save and rechange value a second time just in case.

this one give me result i dont want
&where=`{"OldStartupTV.value:=":"oui"}`
and this one give me nothing
&where=`{"OldStartupTV.value:=":"non"}`

i dont like to missanderstood something like this but i have nor competance nor time to go further, Thanks to every one for dedicated help. i will stick with getressources for this one

Hi @singaii,

I think you shouldn’t give up yet.
Let me see if I can somehow help.

I use pdoTools for everything I code with Modx and it is a great extra. Never found anything that was not working properly.

Some hints from my side:

  • We would need to know how your TV details, but I would suggest that the TV is a List Box (Single-Select) withh input option values of: Oui==1||Non==0
  • Output type of the TV should be Text
  • Then try to edit a value for this TV, save the resource and check on the Database directly how it is being stored on the table modx_site_tmplvar_contentvalues. The ‘value’ field is from where you should guide your query filter.
  • Then on your pdoResources call, you need to filter like this:
&where=`{"OldStartupTV":"1"}`

Omitting the operator is the same as stating OldStartupTV=1

I have several situation having exatly this same scenario.
Please ping me if you need help.

Cheers and good luck!

BR,
JNogueira

&where={"OldStartupTV":"1"}

I seem to recall writing this in this thread about a week ago. :wink:

where={“OldStartupTV”:“1”}`

It reportedly didn’t work for the OP.

Hi Bob,
You are right, sorry. Passed my eyes over the topic quickly and missed it. Sorry for double posting.

No worries. It’s still a good answer. :wink:

Hi , sorry for the delay.

I will try Oui==1||Non==0
fact is, i dont remember it was a possibility (even i’ts tagged in gray under tv property)
I use modx for a time now but i dont crawl database too much, after a quick search on modx_site_tmplvar_contentvalues it content only oui value (why?).
i will give a try on those thing today but i need to change the type of my tv (client change) so may be no more radio button but a drop down list.
maybe some news in few hours.
Thanks all to improving my knowledge on modx,

1 Like

Few week past by but did you tried on instead of oui already?

… after a quick search on modx_site_tmplvar_contentvalues it content only oui value (why?).

In that table each record only stores the one selected option of that TV for one specific resource. (Nothing is stored in that table if the TV is set to its default value.)

The full list of options is in the properties field in the TV object table (modx_site_tmplvars).

I make it work !
Oui==1||Non==0 for checkbox
Non selectionné==1||Séléctionné==2||Inscrite à l'émission==3||En finale==4||Archivée==5 for a single selection list and it work with this style of code for pdoressources :

                    [[pdoResources?
                        &parents=`5`
                        &includeContent=`1`
                        &limit=`[[*StartupTileNbrTV]]`
                        &includeTVs=`HeaderImageTV,StartupStateTV,MakeitFirstStartupTV`
                        &tpl=`StartupTilesTpl`
                        &sortby=`menuindex`
                        &where=`{"StartupStateTV":"2"}`
                    ]]

and i even make my first snippet to retrieve the name of selected item of the list ! :

Status : [[+tv.StartupStateTV:StartupStatus]]

and the StartupStatus snippet

<?php
$input = isset($input) ? $input : "";
 
if ($input == "") return "";
else
{

    switch ($input)
    {
        case ("01") : $statustxt = "Non selectionné";    break;
        case ("02") : $statustxt = "Séléctionné";    break;
        case ("03") : $statustxt = "Inscrite à l'émission";  break;
        case ("04") : $statustxt = "En finale";    break;
        case ("05") : $statustxt = "Archivée";    break;
    }

return "$statustxt";
}

i need to change the name of this snippet in ‘showstatus’ to be clear enough but that work.
Thanks all for the help.
i really need to make more web dev project to improve my skill in modx !
the more I dig, the more interesting things I find

1 Like

Thanks its worked :muscle: