Create a php script ( fpw-swap-thumbnails.php
) with the code below and put it in root of your site:
<?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: in post_secondary-image_thumbnail_id
replace secondary-image
with your registered secondary image id. In $args
add any extra post types into post_type
array.
Make a backup of your database ( just to be safe ). Execute the script. Check results. Remove the script.