WIKI使用導(dǎo)航
站長(zhǎng)百科導(dǎo)航
站長(zhǎng)專(zhuān)題
- 網(wǎng)站推廣
- 網(wǎng)站程序
- 網(wǎng)站賺錢(qián)
- 虛擬主機(jī)
- cPanel
- 網(wǎng)址導(dǎo)航專(zhuān)題
- 云計(jì)算
- 微博營(yíng)銷(xiāo)
- 虛擬主機(jī)管理系統(tǒng)
- 開(kāi)放平臺(tái)
- WIKI程序與應(yīng)用
- 美國(guó)十大主機(jī)
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(), get_post_meta() and add_post_meta().
函數(shù)用某篇文章特別規(guī)定的key,刪除所有的自定義區(qū)。也看看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
例子
默認(rèn)用法
<?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.
假如我們有一個(gè)插件,這個(gè)插件可以向文章添加一些meta參數(shù)值,但是當(dāng)我們卸載插件的時(shí)候,我們想要?jiǎng)h除插件添加的所有的文章 meta keys。假定插件添加keysrelated_posts 和post_inspiration。
To delete all the keys, this would be added to the "uninstall" function:
要?jiǎng)h除所有的keys,需要將下面的內(nèi)容添加到"卸載"函數(shù):
<?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":
或者,如果你想要?jiǎng)h除除了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:
或者可能文章數(shù)字185已經(jīng)刪除了,而且你想要?jiǎng)h除所有提及這個(gè)數(shù)字的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.
更詳細(xì)的例子,請(qǐng)進(jìn)入post_meta函數(shù) 例子網(wǎng)頁(yè)。
Note: Unlike update_post_meta(), This function will delete all fields that match the criteria.
注:與update_post_meta()不同,這個(gè)函數(shù)會(huì)刪除匹配標(biāo)準(zhǔn)的所有的區(qū)。
Parameters
參數(shù)
Related
相關(guān)的
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()