Okay, so I have run into an interesting thing in my coding that I cannot explain so hopefully someone else may.
I have the following loop(s) in my code and it works as expected. It generates an array that I later use to populate a History split into Years (if not current Year) and Months (for the current year).
// posts by month if current year, by year otherwise
// go through each blog
// sort through their years (we count for past years)
// sort through their months if this year
$results = array();
$all_blogs = $site->find('blog')->children()->visible();
foreach ($all_blogs as $blog) {
$blog_entries = $blog->children();
foreach ($blog_entries as $blog_year) {
if ($blog_year->uid() == date("Y")) {
$blog_month_entries = $blog_year->children();
foreach ($blog_month_entries as $blog_month) {
$monthName = $blog_month->uid();
if(!isset($results["Months"][$monthName])) { $results["Months"][$monthName] = 0; }
$results["Months"][$monthName] += $blog_month->children()->count();
}
} else {
if (!isset($results["Years"][$blog_year->uid()])) { $results["Years"][$blog_year->uid()] = 0; }
foreach ( $blog_year->children() as $blog_month ) { $results["Years"][$blog_year->uid()] += 1; }
}
}
}
ksort($results["Years"]);
ksort($results["Months"]);
Now my problem … if I modify the following lines
$blog_entries = $blog->children();
$blog_month_entries = $blog_year->children();
And add ->visible() to them, they return empty objects. At the moment everything is visible, however I obviously want to deal with invisible entries in the future.
Is there something glaringly obvious?
Thanks in advance,
D