结果证明我所有的尝试都是可行的(感谢ehsaan的确认)。问题是,我试图从函数执行时为空的字段中获取数据。(我正在创建一个新的/更新的帖子,但尚未更新该字段)。
Solution (delay the hook):
// Time out the custom field to update AFTER the post has been created/updated
function save_custom() {
global $post;
$post_ID = $post->ID;
$result = get_post_meta( $post_ID, \'wpcf-release-date\', 1 );
// Add a new key "era"
add_post_meta($post_ID, "era", $result, true);
// If there is already a key "era", then update it
if ( ! add_post_meta($post_ID, "era", $result, true) ) {
update_post_meta( $post_ID, "era", $result );
}
}
add_action(\'save_post\', \'save_custom\', 0);
add_action(\'save_post\', \'save_custom\', 10);
add_action(\'save_post\', \'save_custom\', 999);