delete_post_meta()删除文章/页面的自定义栏目(字段)

目录

描述

译文

该函数从指定文章中删除含有指定关键字的所有自定义字段。参见update_post_meta(), get_post_meta() 和add_post_meta()。

原文

This function deletes all custom fields with the specified key, or key and value, from the specified post. See also update_post_meta(), get_post_meta() and add_post_meta().

delete_post_meta() 描述

用法

 <?php delete_post_meta($post_id$meta_key$meta_value); ?> 

delete_post_meta() 用法

参数

$post_id

(integer) (必填) The ID of the post from which you will delete a field.

默认值: None

$meta_key

(string) (必填) The key of the field you will delete.

默认值: None

$meta_value

(mixed) (可选) The value of the field you will delete. This is used to differentiate between several fields with the same key. If left blank, all fields with the given key will be deleted.

默认值: Empty

delete_post_meta() 参数

示例

Default Usage

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.

To delete all the keys use delete_post_meta_by_key( $post_meta_key ). This would be added to the "uninstall" function:

Or, if you wanted to delete all the keys except where post_inspiration was "Sherlock Holmes":

Or maybe post number 185 was just deleted, and you want to remove all related_posts keys that reference it:

For a more detailed example, go to the post_meta Functions Examples page.

Note: Unlike update_post_meta(), This function will delete all fields that match the criteria.

delete_post_meta() 示例

历史

添加于 版本 1.5.0

delete_post_meta() 历史

源文件

delete_post_meta() 函数的代码位于 wp-includes/post.php

delete_post_meta() 源文件

相关