on a multisite I delete a user with:


Fine, but unless I am confusing, it doesn't delete the metadata which may exist for this user...

delete_user_meta() seems to be the function to do this but I don't see how to delete ALL the metadata, without entering the metakeys. (I wanted to avoid writing a DELETE query directly on wp_usermeta table)

Thanks for your help Pierre


Yes, it does delete the usermeta. Here's the code it uses:

$meta = $wpdb->get_col( $wpdb->prepare(
                      "SELECT umeta_id FROM $wpdb->usermeta WHERE user_id = %d", $id ) );
foreach ( $meta as $mid )
    delete_metadata_by_mid( 'user', $mid );

There's identical code in wp_delete_user (for the non-multisite case) and they use the same pattern for deleting taxonomy metadata, post metadata etc. so this seems to be the accepted way, without a direct DELETE.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.