Hello,
I have setup a user relation field, and when I update the WP post author I want to update the ACF field with the same author. I have tried and search allot but could find it. I have the following code:
function prefix_on_update_author($post_id, $post_after, $post_before)
{
if ($post_after->post_author != $post_before->post_author) {
$field_key = “field_55739e09b82d3”;
$value = $post_after->post_author;
update_field( $field_key, $value, $post_id );
}
}
add_action(‘post_updated’, ‘prefix_on_update_author’, 10, 3);
But that it not working properly, sometimes when a user creates a new post it saves the post on another user. Also the post_before is sometimes empty.
Can someone see the issue in this action?