最合适的回答,由SO网友:Frank P. Walentynowicz 整理而成
创建php脚本(fpw-swap-thumbnails.php
) 使用以下代码并将其放在站点的根目录中:
<?php
// load WordPress environment
require( \'wp-load.php\' );
$args = array(
\'posts_per_page\' => -1,
\'post_type\' => array( \'post\', \'page\' ),
\'post_status\' => \'publish\'
);
// get all published posts of type specified in $args
$posts = get_posts( $args );
foreach ( $posts as $post ) {
// get thumbnails ids
$thmbsArray = array(
get_post_meta( $post->ID, \'_thumbnail_id\', true ),
get_post_meta( $post->ID, \'post_secondary-image_thumbnail_id\', true )
);
// if both thumbnails exist then swap their values
if ( ( \'\' != $thmbsArray[ 0 ] ) && ( \'\' != $thmbsArray[ 1 ] ) ) {
update_post_meta( $post->ID, \'_thumbnail_id\', $thmbsArray[ 1 ] );
update_post_meta( $post->ID, \'post_secondary-image_thumbnail_id\', $thmbsArray[ 0 ] );
}
}
?>
NOTE: 在里面
post_secondary-image_thumbnail_id
代替
secondary-image
使用您在中注册的次映像id
$args
将任何额外的帖子类型添加到
post_type
大堆
备份数据库(为了安全起见)。执行脚本。检查结果。删除脚本。