2

So I have three light switches on my blog: 'featured', 'required reading' and 'skills'.

I got the featured section to work with this code:

{% for entry in craft.entries
    .section(['etiquette', 'style','culture','reviews'])
    .where('featured' == 1)
    .orderBy('id desc')
    .limit(4)
    .all()
%}

but when I went to do the reading section I used this code:

{% for entry in craft.entries
    .section([
        'etiquette',
        'style',
        'culture'
    ])
    .where('requiredReading' == 1)
    .orderBy('id desc')
    .limit(12)
    .all()
%}

but i get all the stories with reading and featured switches on. I checked the database and the required reading field is 0. How can I get just the required reading or can you not use more than one lightswitch?

0
3

Try rewriting your element query like so...

craft.entries .section(['etiquette','style','culture']) .requiredReading(true) .orderBy('id desc') .limit(12) .all()

In Craft you can do queries against fields in this way. The where() isn't necessary for what you're trying to achieve.

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