Sorry, should have included some code from the start. Here's a basic idea of what I'm working on:
$numPosts = 0;
$eduOffset = 0;
$flexOffset = 0;
$posts = array();
while ($numPosts < $limit){
if($this->EducationPost()->exists()){
$eduStream = $this->EducationPost()->sort('Created', 'desc')->offsetGet($eduOffset);
}
else
{
$eduStream = null;
}
if($this->FlexPost()->exists()){
$flexStream = $this->FlexPost()->sort('Created', 'desc')->offsetGet($flexOffset);
}
else{
$flexStream = null;
}
if((is_null($flexStream) && !is_null($eduStream)) || $eduStream->column('Created') > $flexStream->column('Created')){
array_push($posts, $eduStream);
$eduOffset++;
$numPosts++;
}
//Further checks like the one above
return $posts;
Essentially, I want to look at all the EducationPosts and FlexPosts associated with the page, then take the most recent $limit number of posts, type agnostic, and return them as an iterable list that I can loop through on the page.
The problems I'm running into are twofold. This implementation fails when I try to check which type of post is more recent (which I could mitigate by changing the way the checks work, but it feels like it'd be overcomplicating the issue) due to the ->column() call. Additionally, when testing just to make sure the returned object is iterable, the template does not iterate through the list of returned objects. the code for this snippet is as follows:
<ul>
<% loop ListPosts(3) %>
<li>$Title</li>
<% end_loop %>
</ul>