export_date_options

Create the date options fields for exporting a given post type.

Description

export_date_options( (string) $post_type = 'post' ); 

Parameters (1)

0. $post_type — Optional. (string) => 'post'
The post type. Default post..

Usage

  1. if ( !function_exists( 'export_date_options' ) ) { 
  2. require_once ABSPATH . '/wp-admin/export.php'; 
  3.  
  4. // The post type. Default 'post'. 
  5. $post_type = 'post'; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = export_date_options($post_type); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/export.php  
  1. function export_date_options( $post_type = 'post' ) { 
  2. global $wpdb, $wp_locale; 
  3.  
  4. $months = $wpdb->get_results( $wpdb->prepare( " 
  5. SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month 
  6. FROM $wpdb->posts 
  7. WHERE post_type = %s AND post_status != 'auto-draft' 
  8. ORDER BY post_date DESC 
  9. ", $post_type ) ); 
  10.  
  11. $month_count = count( $months ); 
  12. if ( !$month_count || ( 1 == $month_count && 0 == $months[0]->month ) ) 
  13. return; 
  14.  
  15. foreach ( $months as $date ) { 
  16. if ( 0 == $date->year ) 
  17. continue; 
  18.  
  19. $month = zeroise( $date->month, 2 ); 
  20. echo '<option value="' . $date->year . '-' . $month . '">' . $wp_locale->get_month( $month ) . ' ' . $date->year . '</option>';