Home › Forums › Backend Issues (wp-admin) › 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"
Sincerly
Grauen
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
update_field("field_5bd57f0208199","".time(),"user_".$current_user->ID);
EDIT:
This is not solved, the value does not get updated in the database:
Code:
`$prevalue= get_field(‘field_5bd57f0208199’,”user_”.$current_user->ID);
error_log(“Pre Value is: “.$prevalue);
update_field(“field_5bd57f0208199″,””.time(),”user_”.$current_user->ID);
$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:`
option_id;option_name;option_value;autoload
176;user__dev_text;1540731036;no
177;_user__dev_text;field_5bd57f0208199;no
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?
The topic ‘update_field Method does not update Field on User Edit Page’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.