0

I have multiple forms which stores extra user fields in usermeta table. For this i use

foreach($user_meta_fields as $user_meta_field){ If($_POST[$user_meta_field] !=''){ update_user_meta($current_user->ID, $user_meta_field, $_POST[$user_meta_field]); } }

But now i like to delete a meta key if an user decides to uncheck that particular input field. How can i do this?

Should i read all stored meta keys and compare with the meta keys in $_POST?

Any suggestions?

  • Why not just use delete_user_meta()? in an else statement? – Andrew Bartel Nov 14 '14 at 0:42
  • @AndrewBartel, i realise i need to use delete_user_meta but i am having trouble with the logic. In my case for example an user has selected input fields a b x y and z. And the next day he selects input fields c x y z, hence he deselects a and b. So how do i setup the logic to delete_user_meta and update_user_meta? regards – alex Nov 14 '14 at 8:09
  • tryint to simplify my issue. Is this logic correct? $meta_fields_from_post = array('c','x','y','z'); $meta_fields_stored = array('a','b','x','y','z'); $fields_filtered_to_delete = array_diff( $meta_fields_from_post, $meta_fields_stored); – alex Nov 14 '14 at 8:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.