使用您的函数在所有帖子上创建一个简单的查询和循环:
//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);
}
}
保存后,将其删除(只需运行一次)。
使用上面的旧函数并将其挂钩以保存\\u post挂钩,这样每次保存一篇文章时,它都会运行
add_action(\'save_post\',\'add_custom_field_automatically\');