On this page
export_date_options( string $post_type = 'post' )
Create the date options fields for exporting a given post type.
Parameters
$post_typestring Optional-
The post type. Default
'post'.Default:
'post'
Source
File: wp-admin/export.php. View all references
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
FROM $wpdb->posts
WHERE post_type = %s AND post_status != 'auto-draft'
ORDER 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 );
echo '<option value="' . $date->year . '-' . $month . '">' . $wp_locale->get_month( $month ) . ' ' . $date->year . '</option>';
}
}
Related
Uses
| Uses | Description |
|---|---|
| zeroise() wp-includes/formatting.php | Add leading zeros when necessary. |
| WP_Locale::get_month() wp-includes/class-wp-locale.php | Retrieves the full translated month by month number. |
| wpdb::get_results() wp-includes/class-wpdb.php | Retrieves an entire SQL result set from the database (i.e., many rows). |
| wpdb::prepare() wp-includes/class-wpdb.php | Prepares a SQL query for safe execution. |
Changelog
| Version | Description |
|---|---|
| 3.1.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/export_date_options