create a simple query and loop over all posts with your function:
//get all your post of that type
my_query = new WP_Query();
my_query->query(array('post_type' => '','posts_per_page' => -1));
if (my_query->have_posts()){
//loop over all post and update meta field with your function
while (my_query->have_posts()){
my_query->the_post();
add_custom_field_automatically_new($post->ID,$post->post_author);
}
}
//save as your function but with bit of tweaking
function add_custom_field_automatically_new($post_ID,$post_a) {
if(!wp_is_post_revision($post_ID)) {
$themevalue = get_the_author_meta('themeperauthor', $post_a);
$themename="themeperauthor";
add_post_meta($post_ID, $themename, $themevalue);
}
}
after you save this remove it (it only needs to run once).
the use your old function from above and hook it to save_post hook so every time a post is saved it will run
add_action('save_post','add_custom_field_automatically');