Support

Account

Home Forums Backend Issues (wp-admin) ACF User author field is overwritten on edit

Solving

ACF User author field is overwritten on edit

  • I have a user field type dropdown from where the author for a CPT can be selected from all the registered WordPress users.

    I’ve noticed that as soon as another user edits that post, this field value is overwritten with that user’s info.

    How can I retain the original author’s info in that field and prevent it from being overwritten with subsequent edits?

  • You have something more going on than just a user field. What you describe should not happen without someone wanting it to happen. Maybe a filter or action is causing this but there’s really not any way for me to tell you where to look.

  • Thanks John. I’ve managed to resolve it with this code snippet as I don’t have any custom filters or actions.

    function action_function_name( $field ) {
    	global $post;
        $id = $post->ID;
    	$value = get_field('user',$id);
    	$args = array(
          'ID' => $id,
          'post_author' => $value,
    	);
    	wp_update_post( $args );
      return $field;
    }
    add_action( 'acf/render_field/name=user', 'action_function_name', 10, 1 );
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.