Reputation: 248
hey i am trying to update user meta but its not updating
$dobs=$_REQUEST['day'].'_'.$_REQUEST['month'].'_'.$_REQUEST['year'];
$gender=$_REQUEST['gender'];
$country=$_REQUEST['country'];
$state=$_REQUEST['state'];
$city=$_REQUEST['city'];
update_user_meta( $user_id, 'date_of_birth', $dobs, true );
update_user_meta((int) $user_id, 'gender', (int) $gender, true );
update_user_meta( $user_id, 'country', $country, true );
update_user_meta( $user_id, 'state', $state, true );
update_user_meta( $user_id, 'city', $city, true );
here i tried typecasting like (int) (string) interesting part is insert working properly don't know if there is an error in DB structure.
Upvotes: 0
Views: 647
Reputation: 4210
update_user_meta() - Update user meta field based on user ID. It has only three arguments in general where the 4th is optional. The 4th parameter is the
$prev_value
which in default will be the '' values alone. Hence the 4th parameter will be checking whether themeta_key
updated has the previous values to it.
For Example:
<?php
$user_id = 1;
$website_url = 'http://wordpress.org';
update_user_meta($user_id, 'user_url', $website_url, TRUE);
// The above statement will update the user_meta table corresponding to the user_id=1
?>
Note: The First 3 Parameters are required. Without that it will not work.
Kindly ensure that the the 'second value' in the update_user_meta() should be existing into the database table.
As per the Question Author Scenario:
update_user_meta( $user_id, 'date_of_birth', $dobs, true );
It must have all the 3 parameters namely $user_id
,date_of_birth
and the $dobs
.
Upvotes: 0
Reputation: 32354
You need to remove the 4th param of the update_user_meta
update_user_meta( $user_id, 'date_of_birth', $dobs );
The 4th param is used by wordpress to update only the fields that have a previous value equal with the value of the 4th param
So wordpress is looking for date_of_birth
that has a previous value of true for that user
more info
Upvotes: 2