WordPress: Function Reference/delete post meta:修订间差异

来自站长百科
跳转至: 导航、​ 搜索
(新页面: ==Description== This function deletes all custom fields with the specified key from the specified post. See also update_post_meta(), [[Wo...)
 
无编辑摘要
第1行: 第1行:
==Description==
==Description==
==描述==
This function deletes all custom fields with the specified key from the specified post. See also [[WordPress:Function Reference/update post meta|update_post_meta()]], [[WordPress:Function Reference/get post meta|get_post_meta()]] and [[WordPress:Function Reference/add post meta|add_post_meta()]].  
This function deletes all custom fields with the specified key from the specified post. See also [[WordPress:Function Reference/update post meta|update_post_meta()]], [[WordPress:Function Reference/get post meta|get_post_meta()]] and [[WordPress:Function Reference/add post meta|add_post_meta()]].  
函数用某篇文章特别规定的key,删除所有的自定义区。也看看[[WordPress:Function Reference/update post meta|update_post_meta()]], [[WordPress:Function Reference/get post meta|get_post_meta()]] 和 [[WordPress:Function Reference/add post meta|add_post_meta()]]。
==Usage==
==Usage==
==用法==
%%% <?php delete_post_meta($post_id, $key, $value); ?> %%%
%%% <?php delete_post_meta($post_id, $key, $value); ?> %%%
%%% <?php delete_post_meta($post_id, $key, $value); ?> %%%
==Examples==
==Examples==
===Default Usage===
===Default Usage===
==例子==
===默认用法===
  <?php delete_post_meta(76, 'my_key', 'Steve'); ?>
  <?php delete_post_meta(76, 'my_key', 'Steve'); ?>
<?php delete_post_meta(76, 'my_key', 'Steve'); ?>
===Other Examples===
===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 <tt>related_posts</tt> and <tt>post_inspiration</tt>.
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 <tt>related_posts</tt> and <tt>post_inspiration</tt>.
假如我们有一个插件,这个插件可以向文章添加一些meta参数值,但是当我们卸载插件的时候,我们想要删除插件添加的所有的文章 meta keys。假定插件添加keys<tt>related_posts</tt> 和<tt>post_inspiration</tt>。


To delete all the keys, this would be added to the "uninstall" function:
To delete all the keys, this would be added to the "uninstall" function:
要删除所有的keys,需要将下面的内容添加到"卸载"函数:
<pre><?php
<pre><?php
   $allposts = get_posts('numberposts=0&post_type=post&post_status=');
   $allposts = get_posts('numberposts=0&post_type=post&post_status=');
第18行: 第46行:
   }
   }
?></pre>
?></pre>
<pre><?php
  $allposts = get_posts('numberposts=0&post_type=post&post_status=');
  foreach( $allposts as $postinfo) {
    delete_post_meta($postinfo->ID, 'related_posts');
    delete_post_meta($postinfo->ID, 'post_inspiration');
  }
?></pre>


Or, if you wanted to delete all the keys except where <tt>post_inspiration</tt> was "Sherlock Holmes":
Or, if you wanted to delete all the keys except where <tt>post_inspiration</tt> was "Sherlock Holmes":
或者,如果你想要删除除了<tt>post_inspiration</tt>是"Sherlock Holmes"之外的所有的keys:


<pre><?php
<pre><?php
第33行: 第75行:
   }
   }
?></pre>
?></pre>
<pre><?php
  $allposts = get_posts('numberposts=0&post_type=post&post_status=');
  foreach( $allposts as $postinfo) {
    delete_post_meta($postinfo->ID, 'related_posts');
    $inspiration = get_post_meta( $postinfo->ID, 'post_inspiration );
    foreach( $inspiration as $value ) {
      if( $value != "Sherlock Holmes" )
        delete_post_meta($postinfo->ID, 'post_inspiration', $value);
    }
  }
?></pre>


Or maybe post number 185 was just deleted, and you want to remove all <tt>related_posts</tt> keys that reference it:
Or maybe post number 185 was just deleted, and you want to remove all <tt>related_posts</tt> keys that reference it:
或者可能文章数字185已经删除了,而且你想要删除所有提及这个数字的<tt>related_posts</tt> keys:
<pre><?php
  $allposts = get_posts('numberposts=0&post_type=post&post_status=');
  foreach( $allposts as $postinfo) {
    delete_post_meta($postinfo->ID, 'related_posts', '185');
  }
?></pre>


<pre><?php
<pre><?php
第43行: 第113行:
   }
   }
?></pre>
?></pre>
For a more detailed example, go to the [[WordPress:Function Reference/post meta Function Examples|post_meta Functions Examples]] page.
For a more detailed example, go to the [[WordPress:Function Reference/post meta Function Examples|post_meta Functions Examples]] page.
更详细的例子,请进入[[WordPress:Function Reference/post meta Function Examples|post_meta函数 例子]]网页。


'''''Note:''' Unlike [[WordPress:Function Reference/update post meta|update_post_meta()]], This function will delete '''all''' fields that match the criteria.''
'''''Note:''' Unlike [[WordPress:Function Reference/update post meta|update_post_meta()]], This function will delete '''all''' fields that match the criteria.''
'''''注:'''与[[WordPress:Function Reference/update post meta|update_post_meta()]]不同,这个函数会删除匹配标准的'''所有的'''区。


==Parameters==
==Parameters==
==参数==
{{Parameter|$post_id|integer|The ID of the post from which you will delete a field.}}
{{Parameter|$post_id|integer|The ID of the post from which you will delete a field.}}
{{Parameter|$post_id|integer|你删除某个区所在文章的ID。}}
{{Parameter|$key|string|The key of the field you will delete.}}
{{Parameter|$key|string|The key of the field you will delete.}}
{{Parameter|$key|string|你将要删除某个区的key。}}
{{Parameter|$value|string|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.|optional}}
{{Parameter|$value|string|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.|optional}}
{{Parameter|$value|string|你将要删除的某个区的参数值。这个参数值是用来区分几个具有相同的key的区。如果这个参数值是空的,那么某个key的所有区都会被删除。|可选择的}}


==Related==
==Related==
==相关的==
[[WordPress:Function Reference/update post meta|update_post_meta()]], [[WordPress:Function Reference/get post meta|get_post_meta()]], [[WordPress:Function Reference/add post meta|add_post_meta()]], [[WordPress:Function Reference/get post custom|get_post_custom()]], [[WordPress:Function Reference/get post custom values|get_post_custom_values()]], [[WordPress:Function Reference/get post custom keys|get_post_custom_keys()]]
[[WordPress:Function Reference/update post meta|update_post_meta()]], [[WordPress:Function Reference/get post meta|get_post_meta()]], [[WordPress:Function Reference/add post meta|add_post_meta()]], [[WordPress:Function Reference/get post custom|get_post_custom()]], [[WordPress:Function Reference/get post custom values|get_post_custom_values()]], [[WordPress:Function Reference/get post custom keys|get_post_custom_keys()]]
[[WordPress:Function Reference/update post meta|update_post_meta()]], [[WordPress:Function Reference/get post meta|get_post_meta()]], [[WordPress:Function Reference/add post meta|add_post_meta()]], [[WordPress:Function Reference/get post custom|get_post_custom()]], [[WordPress:Function Reference/get post custom values|get_post_custom_values()]], [[WordPress:Function Reference/get post custom keys|get_post_custom_keys()]]

2008年7月19日 (六) 10:40的版本

Description

描述

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

函数用某篇文章特别规定的key,删除所有的自定义区。也看看update_post_meta(), get_post_meta()add_post_meta()

Usage

用法

%%% <?php delete_post_meta($post_id, $key, $value); ?> %%%


%%% <?php delete_post_meta($post_id, $key, $value); ?> %%%

Examples

Default Usage

例子

默认用法

<?php delete_post_meta(76, 'my_key', 'Steve'); ?>

<?php delete_post_meta(76, 'my_key', 'Steve'); ?>

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.

假如我们有一个插件,这个插件可以向文章添加一些meta参数值,但是当我们卸载插件的时候,我们想要删除插件添加的所有的文章 meta keys。假定插件添加keysrelated_postspost_inspiration

To delete all the keys, this would be added to the "uninstall" function:

要删除所有的keys,需要将下面的内容添加到"卸载"函数:

<?php
  $allposts = get_posts('numberposts=0&post_type=post&post_status=');

  foreach( $allposts as $postinfo) {
    delete_post_meta($postinfo->ID, 'related_posts');
    delete_post_meta($postinfo->ID, 'post_inspiration');
  }
?>


<?php
  $allposts = get_posts('numberposts=0&post_type=post&post_status=');

  foreach( $allposts as $postinfo) {
    delete_post_meta($postinfo->ID, 'related_posts');
    delete_post_meta($postinfo->ID, 'post_inspiration');
  }
?>


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

或者,如果你想要删除除了post_inspiration是"Sherlock Holmes"之外的所有的keys:

<?php
  $allposts = get_posts('numberposts=0&post_type=post&post_status=');

  foreach( $allposts as $postinfo) {
    delete_post_meta($postinfo->ID, 'related_posts');
    $inspiration = get_post_meta( $postinfo->ID, 'post_inspiration );
    foreach( $inspiration as $value ) {
      if( $value != "Sherlock Holmes" )
        delete_post_meta($postinfo->ID, 'post_inspiration', $value);
    }
  }
?>


<?php
  $allposts = get_posts('numberposts=0&post_type=post&post_status=');

  foreach( $allposts as $postinfo) {
    delete_post_meta($postinfo->ID, 'related_posts');
    $inspiration = get_post_meta( $postinfo->ID, 'post_inspiration );
    foreach( $inspiration as $value ) {
      if( $value != "Sherlock Holmes" )
        delete_post_meta($postinfo->ID, 'post_inspiration', $value);
    }
  }
?>


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

或者可能文章数字185已经删除了,而且你想要删除所有提及这个数字的related_posts keys:

<?php
  $allposts = get_posts('numberposts=0&post_type=post&post_status=');

  foreach( $allposts as $postinfo) {
    delete_post_meta($postinfo->ID, 'related_posts', '185');
  }
?>


<?php
  $allposts = get_posts('numberposts=0&post_type=post&post_status=');

  foreach( $allposts as $postinfo) {
    delete_post_meta($postinfo->ID, 'related_posts', '185');
  }
?>


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

更详细的例子,请进入post_meta函数 例子网页。

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

注:update_post_meta()不同,这个函数会删除匹配标准的所有的区。

Parameters

参数

Related

相关的

update_post_meta(), get_post_meta(), add_post_meta(), get_post_custom(), get_post_custom_values(), get_post_custom_keys()


update_post_meta(), get_post_meta(), add_post_meta(), get_post_custom(), get_post_custom_values(), get_post_custom_keys()