Thank you for waiting.
To programmatically update the featured image (for posts where it doesn't already exist), from an image type custom field, you'll need some custom code:
add_shortcode('custom_featured_image_conversion', 'custom_featured_image_conversion_func');
function custom_featured_image_conversion_func($atts) {
$post_type = $atts['type'];
$field = $atts['field'];
// get all the target posts
$args = array(
'post_type' => $post_type,
'posts_per_page' => -1,
'post_status' => get_post_stati(),
);
$posts_array = get_posts( $args );
foreach ($posts_array as $post) {
// if no featured image is set
if( !(has_post_thumbnail($post->ID)) ) {
// get image URL from field
$field_image_url = types_render_field( $field, array( 'item' => $post->ID, 'output' => 'raw' ) );
// if image exists, set it as a featured image
if(!empty($field_image_url)) {
$image_id = attachment_url_to_postid($field_image_url);
if($image_id > 0) {
set_post_thumbnail( $post->ID, $image_id );
}
}
}
}
}
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.
Next, please create a temporary page and insert this new custom shortcode like this:
[custom_featured_image_conversion type='book' field='media-image']
Note: in this example, we assume that the target post type is "book" and the target image custom field to use as a source is "media-image".
After saving the page, visit it on the front-end so that the code can execute in the backend. The custom code will cycle through all the 'book' type posts, and if a featured image doesn't exist and the image is available in the 'media-image' field, it will attach it as a featured image too.
Once, the code has been executed, you can delete this temporary page.
Note: The custom code examples from our forum are shared to get you started in the right direction. You're welcome to adjust them as needed and for more personalized customization assistance, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/