//hook
function wordpress_wp_get_archives($args = '') {
global $wpdb, $wp_locale;
$defaults = array(
'type' => 'monthly', 'limit' => '',
'format' => 'html', 'before' => '',
'after' => '', 'show_post_count' => false,
'echo' => 1, 'order' => 'DESC',
'post_type' => 'post'
);
$r = wp_parse_args( $args, $defaults );
$sql_where = $wpdb->prepare( "WHERE post_type = %s AND post_status = 'publish'", 'post' );
$where = apply_filters( 'getarchives_where', $sql_where, $r );
$join = apply_filters( 'getarchives_join', '', $r );
$query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC";
$key = md5( $query );
$key = "wp_get_archives:$key:$last_changed";
if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
$results = $wpdb->get_results( $query );
wp_cache_set( $key, $results, 'posts' );
}
return $results;
}
// usage
foreach ( (array) $archives as $key => $result ) {
$url = get_month_link( $result->year, $result->month );
$dt = DateTime::createFromFormat('Y', $result->year);
$checked = '';
$selected = '';
if($currentYear == $result->year && $currentMonth == $result->month) {
$selected = 'selected="selected"';
}
$title = sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $result->month ), $dt->format('y') );
$archOptions .= '';
}