Home Forums Backend Issues (wp-admin) update_field Method does not update Field on User Edit Page


update_field Method does not update Field on User Edit Page

  • I would like to automatically set custom field values, when a user is updating the User-Edit page.

    – I created a temporary text field called “dev_text” with key “field_5bd57f0208199”, which is visible on the user edit page. (I also set a rule that would hide the field from the user edit page but with the same result)

    – I hooked on “personal_options_update”
    add_action( 'personal_options_update', array($this,'update_coordinates') );

    Executed code looks like this:

    	public function update_coordinates(){
    		update_field('field_5bd57f0208199','temp_value', "user_".$current_user->ID);
    		$value= get_field('field_5bd57f0208199',"user_".$current_user->ID);
    		log("user profile updated. Value is: " . $value);

    However this seems not to update the field value.
    I set an default value in the database called “old_Value”.
    After the user updated the profile, page I expect the value for this user to be “temp_value”.

    output is:
    "user profile updated. Value is: old_value"


  • Looks like I’ve got this solved.

    – I added a priority (100) to my action
    – It seems like there is some caching active? I deleted the value in the database manually and then it wouldn’t update the value in the database.
    I guess ACF is comparing the target value with a cached existing value and if it’s equal, the db won’t be updated? Can you please confirm this and add a hint in the documentation?

    I tested it, storing a current timestamp in the custom field and now it gets updated properly


    This is not solved, the value does not get updated in the database:

    `$prevalue= get_field(‘field_5bd57f0208199’,”user_”.$current_user->ID);
    error_log(“Pre Value is: “.$prevalue);
    $postvalue= get_field(‘field_5bd57f0208199’,”user_”.$current_user->ID);
    error_log(“user profile updated. Value is: “.$postvalue);`

    This is the output if you execute the Profile update 2 times:

    [28-Oct-2018 12:50:02 UTC] Pre Value is: 1540730664
    [28-Oct-2018 12:50:02 UTC] user profile updated. Value is: 1540731002
    [28-Oct-2018 12:50:36 UTC] Pre Value is: 1540731002
    [28-Oct-2018 12:50:36 UTC] user profile updated. Value is: 1540731036

    But I can’t find the values in the wp_usermeta-Table ?

    EDIT 2:
    I found an entry int the wp_options-Table:`


    Can you explain
    – Why is the value is not stored in the wp_usermeta-Table ?
    – Where is the reference between this entry and the current user?

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘update_field Method does not update Field on User Edit Page’ is closed to new replies.