Support » Fixing WordPress » Help with user meta logic update and delete when not selected

  • DDT

    (@ddt)


    Hi,

    I am having troubles getting the right logic to delete an user meta key/value when an user has deselect the input field. In my case for example a user has selected input fields a b x y and z (corresponding to extra user meta data). I store these user meta with

    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 the next day he selects input fields c x y z, hence he deselects a and b. How do i setup the logic to delete_user_meta and update_user_meta?

    $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);

    Any tips, suggestions

    regards

  • The topic ‘Help with user meta logic update and delete when not selected’ is closed to new replies.