Auto populate custom fields by post date

Ok, I solved this with a nice function, now the only thing left to do is to find a way to update all of the blog posts. doing this by hand will be really bad

here is the code that I used

add_action( ‘save_post’, ‘myplugin_save_postdata’ );

function myplugin_save_postdata( $post_id ) {

if ( ‘page’ == $_POST[‘post_type’] ) {
if ( ! current_user_can( ‘edit_page’, $post_id ) )
return;
} else {
if ( ! current_user_can( ‘edit_post’, $post_id ) )
return;
}

$mydata = get_the_time(‘Y’); // Do something with $mydata
$mymonth = get_the_time(‘F’);

update_post_meta( $post_id, ‘year_’, $mydata );
update_post_meta( $post_id, ‘month’, $mymonth );
}