Using WordPress ‘delete_usermeta()’ PHP function

The delete_usermeta() WordPress PHP function is used to remove user metadata.

Usage

To use delete_usermeta(), you would typically use it as shown below:

delete_usermeta($user_id, $meta_key, $meta_value);

In this custom example, if you wanted to delete the ‘nickname’ metadata for a user with an ID of 1, you would use:

delete_usermeta(1, 'nickname');

The function will then delete the ‘nickname’ metadata for the user with ID 1.

Parameters

  • $user_id (int) – Required. The ID of the user whose metadata you want to delete.
  • $meta_key (string) – Required. The key of the metadata you want to delete.
  • $meta_value (mixed) – Optional. The value of the metadata you want to delete. Default is ”.

More information

See WordPress Developer Resources: delete_usermeta()

Examples

Deleting ‘nickname’ Metadata

Suppose a user with an ID of 1 has a ‘nickname’ metadata that you want to remove. You would use:

delete_usermeta(1, 'nickname');

This code removes the ‘nickname’ metadata for the user with ID 1.

Deleting ‘description’ Metadata

If you want to delete ‘description’ metadata for a user with an ID of 2:

delete_usermeta(2, 'description');

This line of code will delete the ‘description’ metadata for user with ID 2.

Deleting ‘last_login’ Metadata

To remove ‘last_login’ metadata for a user with an ID of 3:

delete_usermeta(3, 'last_login');

This code removes the ‘last_login’ metadata for the user with ID 3.

Deleting ‘admin_color’ Metadata

For removing ‘admin_color’ metadata of a user with an ID of 4:

delete_usermeta(4, 'admin_color');

This will remove the ‘admin_color’ metadata for the user with ID 4.

Deleting ‘rich_editing’ Metadata

To delete ‘rich_editing’ metadata for a user with an ID of 5:

delete_usermeta(5, 'rich_editing');

This line of code will delete the ‘rich_editing’ metadata for the user with ID 5.