WordPress Version: 6.4
/**
* Creates the date options fields for exporting a given post type.
*
* @global wpdb $wpdb WordPress database abstraction object.
* @global WP_Locale $wp_locale WordPress date and time locale object.
*
* @since 3.1.0
*
* @param string $post_type The post type. Default 'post'.
*/
function export_date_options($post_type = 'post')
{
global $wpdb, $wp_locale;
$months = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month\n\t\t\tFROM {$wpdb->posts}\n\t\t\tWHERE post_type = %s AND post_status != 'auto-draft'\n\t\t\tORDER BY post_date DESC", $post_type));
$month_count = count($months);
if (!$month_count || 1 === $month_count && 0 === (int) $months[0]->month) {
return;
}
foreach ($months as $date) {
if (0 === (int) $date->year) {
continue;
}
$month = zeroise($date->month, 2);
printf('<option value="%1$s">%2$s</option>', esc_attr($date->year . '-' . $month), $wp_locale->get_month($month) . ' ' . $date->year);
}
}