如果要删除所有字段,请直接在数据库或管理区域中删除。但是,如果您想保留每个字段的一个副本,只删除重复项,那么这就有点复杂了。您可以使用复杂的SQL语句直接从数据库中删除,如:
delete from wp_postmeta
where meta_id in (
select *
from (
select meta_id
from wp_postmeta a
where a.meta_key = \'podPressPostSpecific\'
and meta_id not in (
select min(meta_id)
from wp_postmeta b
where b.post_id = a.post_id
and b.meta_key = \'podPressPostSpecific\'
)
) as x
);
如果要删除另一个自定义字段的重复项,请不要忘记在两个位置更改meta\\u键的名称。
或者您可以使用php脚本来实现这一点。示例:
<?php
define(\'WP_USE_THEMES\', false);
require(\'wp-blog-header.php\');
define( \'WP_DEBUG_DISPLAY\', true );
ini_set( \'display_errors\', true );
$allposts = get_posts(\'numberposts=-1&post_type=post&post_status=any\');
$keys = array(\'podPressPostSpecific\', \'aktt_tweeted\', \'podPressMedia\');
foreach ( $keys as $key ) {
foreach( $allposts as $postinfo) {
// Fetch array of custom field values
$postmeta = get_post_meta($postinfo->ID, $key);
if (!empty($postmeta) ) {
// Delete the custom field for this post (all occurrences)
delete_post_meta($postinfo->ID, $key);
// Insert one and only one custom field
update_post_meta($postinfo->ID, $key, $postmeta[0]);
}
}
}
?>