Support

Account

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

Solved

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)

The topic ‘Update post owner based on custom field change’ is closed to new replies.