delete_post_meta

Remove metadata matching criteria from a post.

Description

delete_post_meta( (int) $post_id, (string) $meta_key, (string) $meta_value = '' ); 

You can match based on the key, or key and value. Removing based on key and value, will keep from removing duplicate metadata with the same key. It also allows removing all metadata matching key, if needed.

Parameters (3)

0. $post_id (int)
The post id.
1. $meta_key (string)
Metadata name.
2. $meta_value — Optional. (string) => ''
Metadata value. Must be serializable if non-scalar. Default empty.

Usage

  1. if ( !function_exists( 'delete_post_meta' ) ) { 
  2. require_once ABSPATH . WPINC . '/post.php'; 
  3.  
  4. // The post id. 
  5. $post_id = -1; 
  6.  
  7. // Metadata name. 
  8. $meta_key = ''; 
  9.  
  10. // Optional. Metadata value. Must be serializable if 
  11. // non-scalar. Default empty. 
  12. $meta_value = ''; 
  13.  
  14. // NOTICE! Understand what this does before running. 
  15. $result = delete_post_meta($post_id, $meta_key, $meta_value); 
  16.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/post.php  
  1. function delete_post_meta( $post_id, $meta_key, $meta_value = '' ) { 
  2. // Make sure meta is added to the post, not a revision. 
  3. if ( $the_post = wp_is_post_revision($post_id) ) 
  4. $post_id = $the_post; 
  5.  
  6. return delete_metadata('post', $post_id, $meta_key, $meta_value);