I want to add a meta value to my post , which will be based on another meta value , before publish post . This is what I have tried
add_action('save_post_my_custom_post', 'add_custom_field_automatically' );
function add_custom_field_automatically($post_ID) {
$new_meta_value = get_post_meta($post_ID,'_my_meta_key',TRUE).'to ' .' something new';
add_post_meta($post_ID, '_my_new_meta_key', $new_meta_value, true);
}
But it doesn’t work . The hook fired properly , it saves only “to something new” , but what I expect the value should be “my meta value to something new”