2

I need to edit the date of several posts, change it to a specific date, all posts should have the same date.

How can I achieve this? Is there any fuction to add to the functions.php to add this feature? I cant find a solution.

2 Answers 2

3

Original source : post date

  1. Create admin-script.js at your current theme ( this use js folder )

    jQuery(document).ready(function($){
        $('.inline-edit-col-right .inline-edit-col')
            .append(
                '<label style="margin-top: 3em;"><span class="title">Date</span>'
                + '<div class="timestamp-wrap"><select name="mm">'
                + '<option value="00">Month</option>'
                + '<option value="01">01-January</option>'
                + '<option value="02">02-February</option>'
                + '<option value="03">03-March</option>'
                + '<option value="04">04-April</option>'
                + '<option value="05">05-May</option>'
                + '<option value="06">06-June</option>'
                + '<option value="07">07-July</option>'
                + '<option value="08">08-August</option>'
                + '<option value="09">09-September</option>'
                + '<option value="10">10-October</option>'
                + '<option value="11">11-November</option>'
                + '<option value="12">12-December</option>'
                + '</select>'
                + '<input type="text" autocomplete="off" name="jj" maxlength="2" size="2" value="d" placeholder="d">'
                + ', <input type="text" autocomplete="off" name="aa" maxlength="4" size="4" value="Y" placeholder="Y">'
                + '@ <input type="text" autocomplete="off" name="hh" maxlength="2" size="2" value="H" placeholder="H">'
                + ' : <input type="text" autocomplete="off" name="mn" maxlength="2" size="2" value="i" placeholder="i"></div></label>'
        );
    });
    
    1. Add this to your functions.php theme file

.

function my_enqueue() {
wp_enqueue_script('my_admin_script', get_bloginfo('template_url') . '/js/admin-script.js', array('jquery'), false, true);
}
add_action('admin_init', 'my_enqueue');

function my_bulk_edit($action, $result){
    if ('bulk-posts' == $action && $_GET['mm']!='00' && isset($_GET['jj']) && isset($_GET['aa']) && isset($_GET['hh']) && isset($_GET['mn']) ) {
        $date = $_GET['aa'].'-'.$_GET['mm'].'-'.$_GET['jj'].' '.$_GET['hh'].':'.$_GET['mn'].':00';
        $post_date = date("Y-m-d H:i:s", strtotime($date));
        $post_date_gmt = gmdate("Y-m-d H:i:s",strtotime($date));
        $post_status = (strtotime($post_date) > strtotime(date("Y-m-d H:i:s")))? 'future' : 'publish';

        $post_IDs = array_map('intval', (array) $_GET['post']);
        foreach ($post_IDs as $post_ID) {
            $post_data = array( 'ID' => $post_ID, 'post_date' => $post_date, 'post_date_gmt' => $post_date_gmt, 'post_status' => $post_status, 'edit_date' => true );
            //wp_insert_post( $post_data );
            wp_update_post( $post_data );
        }

    }
}
add_action('check_admin_referer', 'my_bulk_edit', 10, 2);

Here the screenshot

Screenshot

0

all posts should have the same date

Do you mean "all posts on this site" or "some posts on this site"?

If the former, perhaps you should be using pages instead of posts?

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