Home Forums Backend Issues (wp-admin) Update post owner based on custom field change


Update post owner based on custom field change

  • Hello,

    I have this question. One of my custom fields is a field with users. When someone sends me a text to publish, I make a (custom type) post of it, and select the author in that users-field.
    Automatically I am the owner of this post. I like to automatically change the ownership of the post based on the one i selected in the custom field.
    Does anyone have an idea how i can realise that?

    Thanks in advance for using your brains on this 🙂

    Kind regards,
    Hans Stavleu

  • Guess i solved it with the following code:

    function action_function_name( $field ) {
    	global $post;
        $id = $post->ID;
    	$value = get_field('owner',$id);
    	$args = array(
          'ID' => $id,
          'post_author' => $value,
    	wp_update_post( $args );
      return $field;
    add_action( 'acf/render_field/name=owner', 'action_function_name', 10, 1 );
Viewing 2 posts - 1 through 2 (of 2 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.