Filtering pages that have an unchecked checkbox

I have this code in one of my yml files.

$featured_posts = page('blog')->children()->filterBy('options', 'featured');

Always done its job. But, I want to do the opposite. That is filter the posts where the ‘featured’ option is not there.

There is only one option for the checkbox, I am just establishing if it is a featured post. I get that ‘options’ is always set on the page. So my page by default shows:

options:

If I selected a post as featured it will show:

options: featured

How would I only show posts that are not featured? Struggling to figure that out.

Thanks

$featured_posts = page('blog')->children()->filterBy('options', '');

Leave the 2nd value blank…

The alternative would be:

$featured_posts = page('blog')->children()->filterBy('options', '!=', 'featured');

If you’d use a toggle instead, you could filter by true/false

Thanks @texnixe I like that solution better.

To be fair when I realised I had a solution immediately after posting the question, I furiously typed it without thinking too much more about it, I knew I only had seconds before you saw it and thought “sigh… here we go again, he isn’t thinking it through” :rofl:

:rofl:

Ok, next time I’ll watch a movie before I answer… But don’t you complain then that it takes too long.

1 Like