WordPress函数文档delete_post_meta()

删除文章/页面的自定义栏目(字段) 描述 译文 该函数从指定文章中删除含有指定关键字的所有自定义字段。参见up…

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

描述

译文

该函数从指定文章中删除含有指定关键字的所有自定义字段。参见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().

用法

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

参数

$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

示例

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.

历史

添加于 版本 1.5.0

源文件

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

相关

Custom Fields:
the_meta(),
get_post_meta(),
add_post_meta(),
update_post_meta(),
delete_post_meta(),
get_post_custom(),
get_post_custom_values(),
get_post_custom_keys()
(See Also: post_meta Function(函数) Examples)

  • 原文:http://codex.wordpress.org/Function_Reference/delete_post_meta
类别:WordPress函数文档

本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。

评论 (0)COMMENT