This question already has an answer here:

I've been doing some WordPress development for the past few years and never really used the User Meta API within WordPress.

Now with one of my projects requiring to store data unique to a user, I needed to look into it.

One thing I've noticed when I looked at the database is that add_user_meta just creates duplicates when there is already an existing one.

My question is, why does this not override any existing key? And we should check first if the Meta Key already exists and then use update_user_meta? Therefore creating an extra custom function if you would like to overwrite this by default.

marked as duplicate by Community Feb 19 '17 at 22:49

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • @Fayaz, I'm not sure if this is the case. I have multiple rows of the same meta_key and was looking for an answer as why this is. – xvilo Feb 19 '17 at 22:48
  • add_user_meta($user_id, $meta_key, $meta_value, $unique = false) - just provide the last $unique param to true, then you'll not have duplicates. – Fayaz Feb 19 '17 at 22:54

Browse other questions tagged or ask your own question.