delete_post_meta( int $post_id, string $meta_key, mixed $meta_value = '' ): bool
- Since
- 1.5.0
- Source
wp-includes/post.php:2675
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.
Compatibility
- WordPress
- since 1.5.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$post_idint- Post ID.
$meta_keystring- Metadata name.
$meta_valuemixedoptional- Metadata value. If provided, rows will only be removed that match the value.
Must be serializable if non-scalar. Default empty.Default:''
Return value
bool- True on success, false on failure.
Performance profile
How much work a call to delete_post_meta() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Light
- Scaling
- Constant
- Instructions
- 15–16
- Plugin surface
- None
- Called by
- 27
Only touches the object cache, via wp_cache_delete_multiple().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 16.
Nothing here hands control to plugin code.
27 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()one call below delete_post_meta() - serializeserialisation
maybe_serialize()one call below delete_post_meta() - cacheobject cache
wp_cache_delete_multiple()one call below delete_post_meta()
Further down the call graph this can also reach query, option and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 1 distinct outcome
One number would be a lie: the work depends on which branch runs. These are every distinct cost delete_post_meta() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 15–16 | wp_is_post_revision(), delete_metadata() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 16 instructions, 15–16 executed per call, 1 branch. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 2
- wp_is_post_revision()Determines if the specified post is a revision.
- delete_metadata()Deletes metadata for the specified object.
Used by · 27
- Custom_Image_Header::ajax_header_remove()Given an attachment ID for a header image, unsets it as a user-uploaded header image for the active theme.
- WP_Customize_Manager::handle_dismiss_autosave_or_lock_request()Deletes a given auto-draft changeset or the autosave revision for a given changeset or delete changeset lock.
- WP_Customize_Nav_Menus::save_nav_menus_created_posts()Publishes the auto-draft posts that were created for nav menu items.
- WP_Embed::delete_oembed_caches()Deletes all oEmbed caches. Unused by core as of 4.0.0.
- WP_Privacy_Policy_Content::_policy_page_updated()Updates the cached policy info when the policy page is updated.
- WP_Privacy_Policy_Content::get_suggested_policy_text()Checks for updated, added or removed privacy policy information from plugins.
- _wp_delete_customize_changeset_dependent_auto_drafts()Deletes auto-draft posts associated with the supplied changeset.
- delete_post_thumbnail()Removes the thumbnail (featured image) from the given post.
- do_all_enclosures()Performs all enclosures.
- do_all_pingbacks()Performs all pingbacks.
- do_all_trackbacks()Performs all trackbacks.
- set_post_thumbnail()Sets the post thumbnail (featured image) for the given post.
Show all 27
- update_attached_file()Updates attachment file path based on attachment ID.
- wp_check_for_changed_dates()Checks for changed dates for published post objects and save the old date.
- wp_check_for_changed_slugs()Checks for changed slugs for published post objects and save the old slug.
- wp_delete_attachment()Trashes or deletes an attachment.
- wp_delete_post()Trashes or deletes a post or page.
- wp_insert_post()Inserts or updates a post in the database.
- wp_privacy_generate_personal_data_export_file()Generate the personal data export file.
- wp_privacy_process_personal_data_export_page()Intercept personal data exporter page Ajax responses in order to assemble the personal data export file.
- wp_restore_image()Restores the metadata for a given attachment.
- wp_restore_post_revision_meta()Restore the revisioned meta values for a post.
- wp_scheduled_delete()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_untrash_post()Restores a post from the Trash.
- wp_untrash_post_comments()Restores comments for a post from the Trash.
- wp_update_attachment_metadata()Updates metadata for an attachment.
- wp_update_nav_menu_item()Saves the properties of a menu item or create a new one.
Source code
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 );}Changelog
Introduced in 1.5.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 tag, from
src/wp-includes/post.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.