finnlesueurgmailcom - 1 month ago

I have a stream where one of the fields is a set of checkboxes that are used to assign and document to one or more categories. How can I make an entries() query to extract documents which have a particular checkbox? This is what I've tried:

{% set files = entries("ucandance", "documents") .where(request_segment(2), "in", "tags") .get() %}

But .where() takes the arguments in the opposite order.

ryanthompson - 1 month ago

where should be what you use but you want to use LIKE since checkboxes store a serialized value array:

where('tags', 'LIKE', '"%' ~ request_segment(2) ~'%"')

Keep in mind where works exactly like the query builder in Laravel. You're basically using the query builder at this point. The segment part is basically just a wildcard to match the string in the column which again is serialized.

Hope this helps!