Deleting Metadata in WordPress
In the previous articles you learned about that how you can add and update post metadata in WordPress, in this article you can learn how to delete that data. The delete_post_meta() function this use for delete post the metadata.
<?php delete_post_meta( $post_id, $meta_key, $meta_value ); ?>
Following parameters accept by this function:
- $post_id — This is use for the ID of the post to delete metadata from.
- $meta_key — This is use for the name of the metadata field.
- $meta_value — This is use for the value of the metadata field.
Here delete the post metadata you created in previous article:
delete_post_meta( 571, ‘prowp_price’ );
Above example code is deleting the post meta and from the product ID 571. Here didn’t define the $meta_value parameter, that’s why all the prowp_price entries will be deleted from product ID 571.