1

I have a series of entries and I want to only display ones whose dropdown field matches a certain value. At the moment, my unfiltered query is like this:

for item in entry.children.limit(6).orderBy('postDate desc').all()

Now I want to add to that something like .search(dropdownField: value) but that's not working, I get no results. What should it be?

1 Answer 1

1

Dropdown fields support filtering by selected option values, so you should be able to do something like this:

{% for item in entry.children
    .dropdownField('value')
    .all()
%}

Note you need to use the value, IIRC using the label doesn't work. If you only have the label, you can go through the fields service to get the available options and then find the corresponding option value.

This is more accurate than going through the search index, since it uses the fields content column directly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.