How to export all posts from one single day.

I've tried Tools > Export > Post.

But problem is that there's only monthly backup, not date-wise as in "only 5th July 2015".

How can I achieve this?

  • 1
    Build your own version of the plugin.
    – kaiser
    Aug 24, 2015 at 7:35
  • 1
    In case you do so and you are stuck, please edit your post with more information where exactly you are stuck.
    – kaiser
    Aug 24, 2015 at 8:15

1 Answer 1


Enhance the native XML export - with a single day selection

Here's one way to modify the native export with a select box, with all available days:

Single Day Export

Here we assume that there are not "huge" number of days to select from ;-) Otherwise we could use a different kind of user interface.

Step #1

First we can add the HTML for our single day filter by using the export_filters hook:

 * Add our extra HTML
add_action( 'export_filters', function() { 
  <p><ul id="wpse-post-filters" class="wpse-export-filters">
        <label><?php _e( 'Single day:' ); ?></label>
        <select name="wpse_single_day">
          <option value="0"><?php _e( 'Select a day' ); ?></option>
          <?php wpse_export_single_day_options(); ?>

Step #2

Next we need to construct the wpse_export_single_day_options()function. We can simple use a modified version of the export_date_options() core function:

 * Modification of the core export_date_options() function
function wpse_export_single_day_options( $post_type = 'post' ) 
    global $wpdb, $wp_locale;
    $months = $wpdb->get_results( 
            "SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month, Day( post_date ) as day
            FROM {$wpdb->posts}
            WHERE post_type = %s AND post_status != 'auto-draft'
            ORDER BY post_date DESC",
    $month_count = count( $months );
    if ( !$month_count || ( 1 == $month_count && 0 == $months[0]->month ) )

    foreach ( $months as $date ) 
        if ( 0 == $date->year )
        $month = zeroise( $date->month, 2 );
            '<option value="%d-%d-%d">%d. %s %d</option>', 
            $wp_locale->get_month( $month ),

Step #3

To place our HTML within the post filter section, we've to use jQuery to move it in the right place:

 * Append our HTML to the post filter section
add_action( 'admin_head', function() 
    <script type="text/javascript">
            $('#wpse-post-filters').appendTo( $('#post-filters') );
<?php });

Step #4

Then we must take care of the database query. There's no explicit filter for that but we can use the export_args filter, with a little trick:

 * Modify the database queries, indirectly 
add_filter( 'export_args', function( $args )
    // User input
    $date = filter_input( INPUT_GET, 'wpse_single_day' );

    // Let's use DateTime to validate the Y-m-d input, 
    // See here http://stackoverflow.com/a/13194441/2078474
    $dt = DateTime::createFromFormat( 'Y-m-d', $date );

    // Check if the user input is a valid date:
    if( method_exists( $dt, 'format' ) && $Ymd = $dt->format( 'Y-m-d' ) )
        // The from date for the db query:
        $args['start_date'] = $Ymd;

        // I think we can modify the end date, in the db query, with this little trick
        $args['end_date'] =  date( 
                '-1 month', 
                    '+1 day', 
                    strtotime( $Ymd ) 
    return $args;

The demo plugin

I've added the whole plugin here on GitHub.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.