Editing the Template
The easiest solution would be to use a conditional to display the featured image:
if has custom field use it, else use Featured Image
You can get the custom field using get_post_meta()
, which will return an empty string if the specified key isn’t set:
$custom_url = get_post_meta( get_the_ID(), 'old_featured_image_custom_field', true );
You can get the Featured Image using the_post_thumbnail()
, or check for its existence via has_post_thumbnail()
.
Using these, you can set up a conditional output, e.g. like so:
<?php
$custom_url = get_post_meta( get_the_ID(), 'old_featured_image_custom_field', true );
if ( '' != $custom_url ) {
?>
<img src="https://wordpress.stackexchange.com/questions/129849/<?php echo $custom_url; ?>" />
<?php
} else if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
Using a Filter
If you can’t or don’t want to edit the template, you’re in luck: the_post_thumbnail()
calls get_the_post_thumbnail()
, which includes a filter, post_thumbnail_html
:
return apply_filters( 'post_thumbnail_html', $html, $post_id, $post_thumbnail_id, $size, $attr );
So, just write a filter callback using the same method:
function wpse129849_filter_the_post_thumbnail( $html, $post_id ) {
// Try to find custom field value
$custom_url = get_post_meta( $post_id, 'old_featured_image_custom_field', true );
// If it has a value, return it
if ( '' != $custom_url ) {
return '<img src="' . $custom_url . '" />';
}
// otherwise, just return the original post thumbnail html
else {
return $html;
}
}
add_filter( 'post_thumbnail_html', 'wpse129849_filter_the_post_thumbnail', 10, 2 );