I’m using the add() function to add a hand-picked page to the front of a collection, as a highlighted page, based on this example, but it still won’t work.
$highlight = (string)$site->find('home')->highlight(); //from a select field
$entries = $site->grandChildren()->visible()->without($highlight)->sortBy('date', 'asc');
$entries->add($highlight)->flip();
I get is my collection as usual, with an empty page at the end.
The flip() is there so that the added page ends up first, but it’s not even taking effect, so I guess the problem happens just before, at the add().
Already tried supplying the add() with all possible sorts of things (page object, id, uid, etc).
collection does only have add(). but pages inhering from collection has append() as well, right? so using add() on pages will not have the desired effect. append() should be used.
like @lukasbestle corrected me below… above is not right. collection has append and prepend. pages has add.