Home » Functions » delete_post_meta

Function Name: delete_post_meta

In WordPress, the delete_post_meta function is used to remove a specific meta data value associated with a post. Meta data is additional information that can be attached to a post, such as custom fields or other relevant data.

The delete_post_meta function requires three parameters: the post ID, the meta key, and the meta value. The post ID specifies the post from which the meta data will be removed. The meta key identifies the specific meta data field, and the meta value is the value that will be deleted.

This function is particularly useful when you want to remove a specific meta data value from a post. For example, if you have a custom field that stores the author’s name and you want to delete it for a particular post, you can use the delete_post_meta function to achieve that.

Here’s an example usage code:

$post_id = 123; // ID of the post $meta_key = ‘author_name’; // Meta key for the author’s name $meta_value = ‘John Doe’; // Value to be deleted

delete_post_meta($post_id, $meta_key, $meta_value);

In this example, the delete_post_meta function will remove the meta data value ‘John Doe’ associated with the meta key ‘author_name’ from the post with the ID 123.

Remember to replace the values in the example with the appropriate ones for your specific use case.

Overall, the delete_post_meta function provides a straightforward way to remove specific meta data values from WordPress posts, enhancing the flexibility and customization options of your website or application.

Learn More on

WordPress snippets using the delete_post_meta function

Register an account to save your snippets or go Pro to get more features.