19

I have a Resources page and an archived Resources page made up of entries. I want to show all current resources on the main page (this list should not include the archived ones) and on the archived page I only want to show only archived resources. I am using a lightswitch field to toggle whether a resource is archived or not.

The archived-only page works as expected, it shows only the archived resources, using this:

{% set resources = craft.entries.relatedTo({ targetElement: category }).order('title').archivedResource('1') %}

The main page, which should show all resource entries except archived ones actually shows all resources (archived and unarchived). I’m using this code:

{% set resources = craft.entries.relatedTo({ targetElement: category }).order('title').archivedResource('0') %}

It appears that the .archivedResource(‘0’) bit is not having any affect. Should I be using some other method to check whether a switch field is toggled or not?

23

You have to use 'not 1' instead of '0':

{% set resources = craft.entries.relatedTo({ targetElement: category }).order('title').archivedResource('not 1') %}

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.