0

I have added "add_user_meta( $userid, 'last_login',$current_login_time);" instead of "update_user_meta( $userid, 'last_login',$current_login_time);".

Now scenario is I have plenty of MetaKey fields as 'last_login'.

Please advise how can I delete all meta_key i.e. 'last_login' and just keep one the most recent?

Need code or mysql query.

Every help will be very appreciated.

amitdutt24
  • 67
  • 2
  • 10
  • It's often quicker to construct a new table selecting just the data you wish to retain - although I appreciate, that this is a little trickier in an EAV environment. – Strawberry Jul 30 '19 at 08:54
  • Surely, entity-atttribute is defined as unique - so I'm puzzled as to how this error could have occurred !?! – Strawberry Jul 30 '19 at 09:03

1 Answers1

1

you can delete this through mysql query

DELETE 
FROM    wp_usermeta 
WHERE   meta_key = 'last_login'

and if you use update_user_meta, the next your function will run, it would automatically create user meta if it doesn't exist and will update if it exist so it wont create duplicates

silver
  • 4,433
  • 1
  • 18
  • 30
  • Sorry, but this is not the answer as this will delete add metakeys named 'last_login' but i have to keep most recent. – amitdutt24 Aug 23 '19 at 18:17