Collections -> Selection help

I am trying to use Collections - Selection container for the first time.

It’s my understanding that this can pull in a list of resources from anywhere in the tree that meet certain criteria… i.e. parent id = x and tv value = 1

How in the heck do you actually make that happen? I see no field or place in this to add a filter like this other than on the selection’s setting tab:

However this doesn’t work even with the simplest of JSON filters added. What am I missing here?

EDIT: I think I have partially answered my question in that I have to manually add each resource one at a time via the link resource button… which is unfortunate as I have hundreds.

Any way to speed this up or have them added automatically when filter criteria are met?

It looks like the items in a selection are stored in the database table modx_collection_selections.
When you know the Selection-ID you could create an SQL statement that inserts all the data you need. Something like this may work:

-- set start value for the column 'menuindex' (minus 1)
SET @rownum := 3;

-- set selection/collection-ID (here '33') to the correct value and adjust the WHERE conditions
INSERT INTO `modx_collection_selections` (collection, resource, menuindex)
SELECT 33, id, @rownum := @rownum + 1
FROM `modx_site_content`
WHERE parent = 2 AND published = 1 AND deleted = 0
ORDER by menuindex;

Or you could write a snippet that uses the class Collections\Model\CollectionSelection and adds new entries with xPDO.

1 Like