function check_meta( $post_id, $post, $update ) {
$post_type = get_post_type($post_id);
if ( "post" != $post_type ) return;
$video_code_val = get_post_meta( $post_id, 'video_code', true );
// Check if the video_code field has a value.
if ( ! empty( $video_code_val ) ){
//if it does, set post format
set_post_format( $post_id, 'video' );
}
}
add_action( 'save_post', 'check_meta', 999, 3 )
Maybe also try other actions…
If the post is saved via published:
add_action( 'publish_post', 'check_meta', 999, 3 );
or if on if a post is saved as draft:
add_action( 'draft_to_publish', 'check_meta', 999, 3 );
or this updated_post_meta
action might work:
add_action( 'updated_post_meta', 'check_meta', 999, 3 );