I’ve upgraded a site I’m working on to the latest WP, but it appears the function I wrote for splitting wp_get_archives() into years is now broken and I can’t find out why. I’ve turned on debugging, but not getting any errors.
Can anyone see what’s wrong please?
Class OSUYMArchives
{
public static function init()
{
/*-----------------------------------------------------------------------------------------------*/
/* GET MONTHLY ARCHIVE DIVIDED TO YEARS */
/*-----------------------------------------------------------------------------------------------*/
/*
* splits:
* <h3>$Year</h3>
* <ul>
* <li><a>$MonthName</a> $Number posts</li>
* </ul>
*/
function get_by_year($sql, $args) {
global $wpdb;
return $sql .= $wpdb->prepare(" AND YEAR(`post_date`) = '%s'", $args['year']); // modify the sql query based on year
}
function osu_ym_archive() {
$archiveString = wp_get_archives('type=yearly&echo=0');
// Find our strings to match
preg_match_all("#title='(d{4})'#", $archiveString, $matches);
foreach ($matches[1] as $year):
echo "<h3>" . $year . "</h3>";
add_filter('getarchives_where', "get_by_year" , 666, 2);
// Set args for new wp_get_archives();
$args = array(
'type' => 'monthly',
'echo' => 0,
'before' => '<span class="cs-color">⢠</span>',
'show_post_count' => 1,
'year' => $year
);
$monthlyArchives = preg_replace('#(.+)(sd{4})(</.+>)#', "$1 $3", wp_get_archives($args));
// Add span with class to post count numbers
$monthlyArchives = str_replace( '(', '(<span class="cs-color">', $monthlyArchives );
$monthlyArchives = str_replace( ')', '</span>)', $monthlyArchives );
// Spit out monthly archives
echo "<ul>" . $monthlyArchives . "</ul>";
remove_filter('getarchives_where', 666);
endforeach;
}
}
} // End OSUYMArchives Class
// Load Class
OSUYMArchives::init();