-$dateoptions = $edateoptions = '';
-$types = "'" . implode("', '", get_post_types( array( 'public' => true, 'can_export' => true ), 'names' )) . "'";
-$stati = "'" . implode("', '", get_post_stati( array( 'internal' => false ), 'names' )) . "'";
-if ( $monthyears = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, YEAR(DATE_ADD(post_date, INTERVAL 1 MONTH)) AS `eyear`, MONTH(DATE_ADD(post_date, INTERVAL 1 MONTH)) AS `emonth` FROM $wpdb->posts WHERE post_type IN ($types) AND post_status IN ($stati) ORDER BY post_date ASC ") ) {
- foreach ( $monthyears as $k => $monthyear )
- $monthyears[$k]->lmonth = $wp_locale->get_month( $monthyear->month, 2 );
- for( $s = 0, $e = count( $monthyears ) - 1; $e >= 0; $s++, $e-- ) {
- $dateoptions .= "\t<option value=\"" . $monthyears[$s]->year . '-' . zeroise( $monthyears[$s]->month, 2 ) . '">' . $monthyears[$s]->lmonth . ' ' . $monthyears[$s]->year . "</option>\n";
- $edateoptions .= "\t<option value=\"" . $monthyears[$e]->eyear . '-' . zeroise( $monthyears[$e]->emonth, 2 ) . '">' . $monthyears[$e]->lmonth . ' ' . $monthyears[$e]->year . "</option>\n";
+function export_date_options() {
+ global $wpdb, $wp_locale;
+
+ $months = $wpdb->get_results( "
+ SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
+ FROM $wpdb->posts
+ WHERE post_type = 'post' AND post_status != 'auto-draft'
+ ORDER BY post_date DESC
+ " );
+
+ $month_count = count( $months );
+ if ( !$month_count || ( 1 == $month_count && 0 == $months[0]->month ) )
+ return;
+
+ foreach ( $months as $date ) {
+ if ( 0 == $date->year )
+ continue;
+
+ $month = zeroise( $date->month, 2 );
+ echo '<option value="' . $date->year . '-' . $month . '" />' . $wp_locale->get_month( $month ) . ' ' . $date->year . '</option>';