1

Some of my entries have the optional plaintext field myCustomField. I want to retrieve all entries except those where myCustomField is filled out.

I can get all entries that have an empty myCustomField

craft.entries({
    myCustomField: ':empty:',
})

but that doesn't include entries that don't have the field myCustomField.

1

I don't know if you can do that at query level without adding the field to your other sections but you can do (although it's not very economical):

{% set entries = craft.entries.all() %}

{% for entry in entries %}
{% if entry.text is empty %}
    {{ entry.title }} <br>
{% endif %}
{% endfor %}
  • Yeah that's what pretty much what I'm doing — looping through all the results to build a new array. But like you said it's costly – henry Mar 4 '19 at 22:15
1

I've found that this is possible for lightswitch fields:

craft.entries.myLightswitchField(':empty:')

aka

craft.entries({
    myLightswitchField: ':empty:'
})

returns all entries where the lightswitch field is toggled off and entries that don't have the lightswitch field.

Not a solution for my text field need, but similar enough that it may be useful for other people.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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