Support

Account

Home Forums Backend Issues (wp-admin) Problem with user field and author update field

Unread

Problem with user field and author update field

  • 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?

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.