Control featured projects with checkboxes

Hi everyone,

I want to feature chosen projects on a different page via checkboxes.
This is what I have right now, but it only outputs one project and only works if one checkbox is checked:

<?php foreach(page('editorial')->children()->visible() as $project): ?>
<?php if($project->uid() == $page->feateditorial()): ?>

<figure class="header-intro-img">
<?php if($image = $project->images()->sortBy('sort', 'asc')->first()): ?>
<img src="<?php echo $image->url() ?>" alt="<?php echo $project->title()->html() ?>">
<?php endif ?>
</figure>

<?php endif ?>
<?php endforeach ?>

What is the best way to achieve this with more than one checked checkbox?

You can use a custom filter:

<?php
$uids = $page->feateditorial()->split();
$projects = page('editorial')->children()->visible()->filter(function($child) use($uids) {
  return in_array($child->uid(), $uids);
});

<?php foreach($projects as $project): ?>
//do stuff
<?php endforeach ?>
1 Like

Thank you @texnixe,
exactly what I was looking for :slight_smile: