SCC
September 15, 2020, 10:56pm
1
Hi, wondering how to do this, not something I have tried before.
If I add checkbox to my blog blueprint to indicate it is a featured post:
postoptions:
label: Post Options
type: checkboxes
options:
featured: Featured
I know I can use something like this to get the posts from my blog
$posts = $page->children()->listed()->flip();
What I am not sure of is how I would amend the above to only return those posts where the checkbox I have just added is checked.
Any help appreciated, I have look at the docs but can’t figure it out. #newbie
Thanks
SCC
September 15, 2020, 11:03pm
2
Sorry, I did have it figured, turns out I didn’t save the only post where I checked the checkbox!
$featured = $page->children()->filterBy('postoptions', 'featured', true);
The answer above just in case anyone else needs it.
texnixe
September 16, 2020, 4:43am
3
Since your are using a checkboxes field, this will store the value featured
when checked, not true
. So the third option on your filterBy
is actually superfluous and misleading, should be
$featured = $page->children()->filterBy('postoptions', 'featured');
As a third option you could pass the separator in this example, which isn’t necessary here.
1 Like