0

The question is simple. I have a phone number that I want to update in the user profile using update_user_meta:

$update = update_user_meta( 15, 'billing_phone', '79998887766' );

if ( false === $update ) {
    echo 'not updated';
} else {
    echo 'updated';
}

As a result, the phone number is updated successfully, but the function returns false:

not updated

This function should return (int|bool) Meta ID if the key didn't exist, true on successful update, false on failure. I can't figure out what the reason is.

Alex
  • 1
  • At first sight, you're using `===`, does it make a difference if you use `== `? [Difference between == and ===](https://stackoverflow.com/a/80649/11987538). Also try `echo gettype($update);` – 7uc1f3r May 20 '20 at 19:14
  • Replacing === with == gives the same result, and echo gettype($update); returns boolean. In addition, I care very much about the cleanliness of the wordpress engine and prefer not to use plugins unless absolutely necessary. Therefore, this behavior of the function concerned me. – Alex May 21 '20 at 18:09
  • Well, just tested your code and it does work so it must go wrong elsewhere. You will need to update your question with more details/full code, maybe that's where the solution can be found. – 7uc1f3r May 21 '20 at 19:53
  • https://developer.wordpress.org/reference/functions/update_user_meta/ also be aware that if the meta value is the same as it was before update_user_meta will also return false. – David Jarrin Apr 04 '22 at 17:00

0 Answers0