久久精品水蜜桃av综合天堂,久久精品丝袜高跟鞋,精品国产肉丝袜久久,国产一区二区三区色噜噜,黑人video粗暴亚裔

WordPress:Function Reference/delete post meta

來自站長(zhǎng)百科
Xxf3325討論 | 貢獻(xiàn)2008年7月18日 (五) 10:36的版本 (新頁面: ==Description== This function deletes all custom fields with the specified key from the specified post. See also update_post_meta(), [[Wo...)
(差異) ←上一版本 | 最后版本 (差異) | 下一版本→ (差異)
跳轉(zhuǎn)至: 導(dǎo)航、? 搜索

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().

Usage

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

Examples

Default Usage

<?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.

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

<?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":

<?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:

<?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.

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

Parameters

Related

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