David_George
David_George

Reputation: 51

Updating new database row along with meta_key and meta_value on wordpress

I have added a new row into the user_meta table in my wordpress database and need to update this along with the meta_key and meta_value using update_user_meta

The table currently looks as follows:

[umeta_id][user_id][meta_key][meta_value][date]

I need to do something like:

update_user_meta($userid, 'meta_key' , 'meta_value' , 'value for date field')

Is this possible and if so what would be the best way to do this.

Thanks for any help anyone can offer.

Upvotes: 0

Views: 247

Answers (1)

Purvik Dhorajiya
Purvik Dhorajiya

Reputation: 4870

If you want to store multiple parameters? In this case, you need to serialize them before saving them in the user’s meta field:

$meta_value = array(
    'field1' => 'YOUR_FIELD1_VALUE',
    'field2' => 'YOUR_FIELD2_VALUE'
    );
$final_data = serialize( $meta_value ); 

update_user_meta( $user_id, 'YOUR_META_KEY', $final_data);

And if you want to get them back:

$user_data = get_user_meta( $user_id, 'YOUR_META_KEY', true ); 
$mydata = unserialize($user_data);

echo "<pre>";
print_r($mydata);
echo "</pre>";

Upvotes: 0

Related Questions