$collection = pages();
if ($bonuses) {
foreach ($bonuses as $bonus) {
foreach ($bonus->bonus_offers()->toStructure() as $bonus_offer) {
$collection->add($bonus);
}
}
$bonuses = $collection;
}
the problem is some reviews could have 2-3 bonuses, and i wish to create listing that could repeat reivew logo, url but have different bonus options that is placed in bonus_offers structure field
Maybe preset more simple way how can I do it?
Right now I have only one review in listing, even if this review have more than one bonus…
Then in your template, loop through the filtered reviews:
<?php
if ($reviewsWithBonus->count()):
foreach ($reviewsWithBonus as $review):
foreach ($review->bonus_offers()->toStructure() as $bonus):
// echo the fields of bonus offer
endforeach;
endforeach;
endif;
<?php
if ($reviewsWithBonus->count()):
foreach ($reviewsWithBonus as $review):
foreach ($review->bonus_offers()->toStructure() as $bonus):
// echo the fields of bonus offer
endforeach;
endforeach;
endif;
to this (after creating in controller $sortedReviews filter):
<?php
if ($sortedReviews->count()):
foreach ($sortedReviews as $review):
foreach ($review->bonus_offers()->toStructure() as $bonus):
// echo the fields of bonus offer
endforeach;
endforeach;
endif;
The question is what exactly you want to achieve. We are sorting the reviews here, not the bonuses. If you want to sort all bonuses of all structure fields by date, then the code would have to be different.
Ah, ok, that was not clear from your first explanation. To achieve this, you have to fetch all structure field entries from all review pages into one collection (like you tried in your first post), but not into a pages collection, but into a new structure.