Merge pages and keep duplicates

Hello,

I am trying to merge() a set of pages into a larger group that already includes these pages. I would like to allow duplicates.

My current code is:

<?php // Get all pages with the "project" template

$projects = site()->pages()->filterBy('intendedTemplate', 'project')->listed();
$count = $projects->count();

// Check if the count is not a multiple of 10
if ($count % 10 !== 0) {
  // Calculate how many projects are needed to make the count a multiple of 10
  $needed = 10 - ($count % 10);

  // Get a shuffled list of additional projects and limit to the needed amount
  $additionalProjects = $projects->shuffle()->limit($needed);

  // Add the additional projects to the original set of projects
  $projects = $projects->merge($additionalProjects);
}

?>

This is is not allowing duplicate pages, so the $additionalProjects are never added properly.

What would be the best way around this?

Thank you!

Does $pages->add() | Kirby CMS work for you instead?

See Add the same page to a collection multiple times - #2 by texnixe