可以使用以下SQL语句直接从数据库中删除:
delete from wp_postmeta
where meta_id in (
select *
from (
select meta_id
from wp_postmeta a
where a.meta_key = \'blogger_blog\'
and meta_id not in (
select min(meta_id)
from wp_postmeta b
where b.post_id = a.post_id
and b.meta_key = \'blogger_blog\'
)
) 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(\'blogger_blog\', \'blogger_author\', \'blogger_permalink\');
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]);
}
}
}
?>