Way to have getResources not show unpublished IDs if given a list of IDs

324 Views Asked by At

I've got an SQL query that spits out a group of IDs. I feed these IDs to a getResources call as such:

         [[getResources?
                &parents=`4`
                &resources=`' . $ids . '`
                &limit=`0`
                &showHidden=`1`
                &tpl=`PropItemTPL`
                &sortby=`menuindex ASC, id`
                &sortdir=`ASC`
                &includeContent=`1`
                &includeTVs=`1`
                &processTVs=`1`
                &showUnpublished=`0`
           ]]

Problem is this shows all IDs, even if they're unpublished.

I've included &showUnpublished='0' but this makes no difference.

Would anyone know if there's a way to have this work with getResources? Or do I need to re-write my PHP and MySQL?

2

There are 2 best solutions below

0
On BEST ANSWER

The resources parameter is separate from the rest of the selection logic. If you include a resource's id in the resources property, it will be included regardless of any other selection properties.

Try pdoResources and I don't think you'll have this problem. It's also much quicker than getResources.

0
On

You can add "where" clause as one of your parameters, narrowing result set to only published documents:

[[getResources?
                &parents=`4`
                &resources=`' . $ids . '`
                &limit=`0`
                &showHidden=`1`
                &tpl=`PropItemTPL`
                &sortby=`menuindex ASC, id`
                &sortdir=`ASC`
                &includeContent=`1`
                &includeTVs=`1`
                &processTVs=`1`
                &where=`{"published" : true}`
           ]]