Title: delete_post_meta
Published: April 25, 2014
Last modified: February 24, 2026

---

# delete_post_meta( int $post_id, string $meta_key, mixed $meta_value ): bool

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/delete_post_meta/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/delete_post_meta/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/delete_post_meta/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/delete_post_meta/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/delete_post_meta/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/delete_post_meta/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/delete_post_meta/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/delete_post_meta/?output_format=md#wp--skip-link--target)

Deletes a post meta field for the given post ID.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/delete_post_meta/?output_format=md#description)󠁿

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 the key, if needed.

For historical reasons both the meta key and the meta value are expected to be “
slashed” (slashes escaped) on input.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/delete_post_meta/?output_format=md#parameters)󠁿

 `$post_id`intrequired

Post ID.

`$meta_key`stringrequired

Metadata name.

`$meta_value`mixedoptional

Metadata value. If provided, rows will only be removed that match the value.
 Must
be serializable if non-scalar. Default empty.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/delete_post_meta/?output_format=md#return)󠁿

 bool True on success, false on failure.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/delete_post_meta/?output_format=md#source)󠁿

    ```php
    function delete_post_meta( $post_id, $meta_key, $meta_value = '' ) {
    	// Make sure meta is deleted from the post, not from a revision.
    	$the_post = wp_is_post_revision( $post_id );
    	if ( $the_post ) {
    		$post_id = $the_post;
    	}

    	return delete_metadata( 'post', $post_id, $meta_key, $meta_value );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/post.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/post.php#L2679)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/post.php#L2679-L2687)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/delete_post_meta/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_is_post_revision()](https://developer.wordpress.org/reference/functions/wp_is_post_revision/)`wp-includes/revision.php` |

Determines if the specified post is a revision.

  | 
| [delete_metadata()](https://developer.wordpress.org/reference/functions/delete_metadata/)`wp-includes/meta.php` |

Deletes metadata for the specified object.

  |

| Used by | Description | 
| [wp_restore_post_revision_meta()](https://developer.wordpress.org/reference/functions/wp_restore_post_revision_meta/)`wp-includes/revision.php` |

Restore the revisioned meta values for a post.

  | 
| [do_all_trackbacks()](https://developer.wordpress.org/reference/functions/do_all_trackbacks/)`wp-includes/comment.php` |

Performs all trackbacks.

  | 
| [do_all_enclosures()](https://developer.wordpress.org/reference/functions/do_all_enclosures/)`wp-includes/comment.php` |

Performs all enclosures.

  | 
| [do_all_pingbacks()](https://developer.wordpress.org/reference/functions/do_all_pingbacks/)`wp-includes/comment.php` |

Performs all pingbacks.

  | 
| [wp_check_for_changed_dates()](https://developer.wordpress.org/reference/functions/wp_check_for_changed_dates/)`wp-includes/post.php` |

Checks for changed dates for published post objects and save the old date.

  | 
| [WP_Privacy_Policy_Content::get_suggested_policy_text()](https://developer.wordpress.org/reference/classes/wp_privacy_policy_content/get_suggested_policy_text/)`wp-admin/includes/class-wp-privacy-policy-content.php` |

Checks for updated, added or removed privacy policy information from plugins.

  | 
| [WP_Privacy_Policy_Content::_policy_page_updated()](https://developer.wordpress.org/reference/classes/wp_privacy_policy_content/_policy_page_updated/)`wp-admin/includes/class-wp-privacy-policy-content.php` |

Updates the cached policy info when the policy page is updated.

  | 
| [wp_privacy_process_personal_data_export_page()](https://developer.wordpress.org/reference/functions/wp_privacy_process_personal_data_export_page/)`wp-admin/includes/privacy-tools.php` |

Intercept personal data exporter page Ajax responses in order to assemble the personal data export file.

  | 
| [wp_privacy_generate_personal_data_export_file()](https://developer.wordpress.org/reference/functions/wp_privacy_generate_personal_data_export_file/)`wp-admin/includes/privacy-tools.php` |

Generate the personal data export file.

  | 
| [WP_Customize_Manager::handle_dismiss_autosave_or_lock_request()](https://developer.wordpress.org/reference/classes/wp_customize_manager/handle_dismiss_autosave_or_lock_request/)`wp-includes/class-wp-customize-manager.php` |

Deletes a given auto-draft changeset or the autosave revision for a given changeset or delete changeset lock.

  | 
| [_wp_delete_customize_changeset_dependent_auto_drafts()](https://developer.wordpress.org/reference/functions/_wp_delete_customize_changeset_dependent_auto_drafts/)`wp-includes/nav-menu.php` |

Deletes auto-draft posts associated with the supplied changeset.

  | 
| [WP_Customize_Nav_Menus::save_nav_menus_created_posts()](https://developer.wordpress.org/reference/classes/wp_customize_nav_menus/save_nav_menus_created_posts/)`wp-includes/class-wp-customize-nav-menus.php` |

Publishes the auto-draft posts that were created for nav menu items.

  | 
| [wp_restore_image()](https://developer.wordpress.org/reference/functions/wp_restore_image/)`wp-admin/includes/image-edit.php` |

Restores the metadata for a given attachment.

  | 
| [Custom_Image_Header::ajax_header_remove()](https://developer.wordpress.org/reference/classes/custom_image_header/ajax_header_remove/)`wp-admin/includes/class-custom-image-header.php` |

Given an attachment ID for a header image, unsets it as a user-uploaded header image for the active theme.

  | 
| [wp_scheduled_delete()](https://developer.wordpress.org/reference/functions/wp_scheduled_delete/)`wp-includes/functions.php` |

Permanently deletes comments or posts of any type that have held a status of ‘trash’ for the number of days defined in EMPTY_TRASH_DAYS.

  | 
| [WP_Embed::delete_oembed_caches()](https://developer.wordpress.org/reference/classes/wp_embed/delete_oembed_caches/)`wp-includes/class-wp-embed.php` |

Deletes all oEmbed caches. Unused by core as of 4.0.0.

  | 
| [set_post_thumbnail()](https://developer.wordpress.org/reference/functions/set_post_thumbnail/)`wp-includes/post.php` |

Sets the post thumbnail (featured image) for the given post.

  | 
| [delete_post_thumbnail()](https://developer.wordpress.org/reference/functions/delete_post_thumbnail/)`wp-includes/post.php` |

Removes the thumbnail (featured image) from the given post.

  | 
| [wp_check_for_changed_slugs()](https://developer.wordpress.org/reference/functions/wp_check_for_changed_slugs/)`wp-includes/post.php` |

Checks for changed slugs for published post objects and save the old slug.

  | 
| [wp_delete_attachment()](https://developer.wordpress.org/reference/functions/wp_delete_attachment/)`wp-includes/post.php` |

Trashes or deletes an attachment.

  | 
| [wp_update_attachment_metadata()](https://developer.wordpress.org/reference/functions/wp_update_attachment_metadata/)`wp-includes/post.php` |

Updates metadata for an attachment.

  | 
| [wp_untrash_post_comments()](https://developer.wordpress.org/reference/functions/wp_untrash_post_comments/)`wp-includes/post.php` |

Restores comments for a post from the Trash.

  | 
| [wp_insert_post()](https://developer.wordpress.org/reference/functions/wp_insert_post/)`wp-includes/post.php` |

Inserts or update a post.

  | 
| [wp_delete_post()](https://developer.wordpress.org/reference/functions/wp_delete_post/)`wp-includes/post.php` |

Trashes or deletes a post or page.

  | 
| [wp_untrash_post()](https://developer.wordpress.org/reference/functions/wp_untrash_post/)`wp-includes/post.php` |

Restores a post from the Trash.

  | 
| [update_attached_file()](https://developer.wordpress.org/reference/functions/update_attached_file/)`wp-includes/post.php` |

Updates attachment file path based on attachment ID.

  | 
| [wp_update_nav_menu_item()](https://developer.wordpress.org/reference/functions/wp_update_nav_menu_item/)`wp-includes/nav-menu.php` |

Saves the properties of a menu item or create a new one.

  |

[Show 22 more](https://developer.wordpress.org/reference/functions/delete_post_meta/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/delete_post_meta/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/delete_post_meta/?output_format=md#changelog)󠁿

| Version | Description | 
| [1.5.0](https://developer.wordpress.org/reference/since/1.5.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/delete_post_meta/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 5 content](https://developer.wordpress.org/reference/functions/delete_post_meta/?output_format=md#comment-content-621)
 2.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/delete_post_meta/#comment-621)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fdelete_post_meta%2F%23comment-621)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fdelete_post_meta%2F%23comment-621)
 4.  **Other Examples**
      Let’s assume we had a plugin that added some meta values to
     posts, but now when we are uninstalling the plugin, we want to delete all the 
     post meta keys that the plugin added. Assuming the plugin added the keys `related_posts`
     and `post_inspiration`.
 5.  To delete all the keys use `delete_post_meta_by_key( $post_meta_key )`. This would
     be added to the “uninstall” function:
 6.      ```php
         <?php delete_post_meta_by_key( 'related_posts' ); ?>
         ```
     
 7.  Or, if you wanted to delete all the keys except where `post_inspiration` was “
     Sherlock Holmes”:
 8.      ```php
         <?php
         $allposts = get_posts( 'numberposts=-1&post_type=post&post_status=any' );
     
         foreach( $allposts as $postinfo ) {
         	delete_post_meta( $postinfo->ID, 'related_posts' );
         	$inspiration = get_post_meta( $postinfo->ID, 'post_inspiration' );
         	foreach( $inspiration as $value ) {
         		if( 'Sherlock Holmes' !== $value )
         			delete_post_meta( $postinfo->ID, 'post_inspiration', $value );
         	}
         }
         ?>
         ```
     
 9.  Or maybe post number 185 was just deleted, and you want to remove all `related_posts`
     keys that reference it:
 10.     ```php
         <?php
           $allposts = get_posts( 'numberposts=-1&post_type=post&post_status=any' );
     
           foreach( $allposts as $postinfo ) {
             delete_post_meta( $postinfo->ID, 'related_posts', '185' );
           }
         ?>
         ```
     
 11.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fdelete_post_meta%2F%3Freplytocom%3D621%23feedback-editor-621)
 12.  [Skip to note 6 content](https://developer.wordpress.org/reference/functions/delete_post_meta/?output_format=md#comment-content-620)
 13.   [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/delete_post_meta/#comment-620)
 14. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fdelete_post_meta%2F%23comment-620)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fdelete_post_meta%2F%23comment-620)
 15. **Default Usage**
 16.     ```php
         <?php delete_post_meta(76, 'my_key', 'Steve'); ?>
         ```
     
 17.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fdelete_post_meta%2F%3Freplytocom%3D620%23feedback-editor-620)
 18.  [Skip to note 7 content](https://developer.wordpress.org/reference/functions/delete_post_meta/?output_format=md#comment-content-3649)
 19.   [Michelle Blanchette](https://profiles.wordpress.org/michelleblanchette/)  [  6 years ago  ](https://developer.wordpress.org/reference/functions/delete_post_meta/#comment-3649)
 20. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fdelete_post_meta%2F%23comment-3649)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fdelete_post_meta%2F%23comment-3649)
 21. Be VERY careful when using this function to delete a specific key-value pair. 
     As stated in [`delete_metadata()`‘s documentation](https://developer.wordpress.org/reference/functions/delete_metadata/),
     providing an empty string for `$meta_value` will cause the check to be skipped
     entirely, resulting in all keys being deleted!
 22. > **$meta_value** …If specified, only delete metadata entries with this value.
     > _Otherwise, delete all entries with the specified meta\_key_…
 23. To avoid accidentally deleting ALL key instances, use a short-circuit check:
 24.     ```php
         $value_to_delete = My_Class::get_value(); // may return empty string
         if ( $value_to_delete != '' && delete_metadata( 'post', 27, 'key', $value_to_delete ) ) {
          // the key-value pair was safely deleted
         }
         ```
     
 25.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fdelete_post_meta%2F%3Freplytocom%3D3649%23feedback-editor-3649)
 26.  [Skip to note 8 content](https://developer.wordpress.org/reference/functions/delete_post_meta/?output_format=md#comment-content-6235)
 27.   [Pacicio](https://profiles.wordpress.org/pacicio/)  [  3 years ago  ](https://developer.wordpress.org/reference/functions/delete_post_meta/#comment-6235)
 28. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fdelete_post_meta%2F%23comment-6235)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fdelete_post_meta%2F%23comment-6235)
 29. If you want to delete all entries with a specified `meta_key`, regardless of the
     field value, you need to set `meta_value` as `null`, otherwise the function will
     return `false` and the field does not get deleted
 30.     ```php
         delete_post_meta( $post_id, $meta_key, null ) 
         ```
     
 31.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fdelete_post_meta%2F%3Freplytocom%3D6235%23feedback-editor-6235)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fdelete_post_meta%2F)
before being able to contribute a note or feedback.