Almost all my custom post types have a custom image field called "representational image". I am using the Divi theme. What I would like is that the "representational image" is automatically set as the feature image for each post type. Note that I am using frontend post forms to add in content, so when I add or update content using frontend forms, a code snippet should be triggered that makes the representational image field's value the same as the featured image field's value.
Is there any documentation that you are following?
I looked everywhere but did not find a definite solution.
Is there a similar example that we can see?
Setting the feature Images programmatically requires some custom code hooked to the save_post action, The image that you are uploading through custom fields holds the image Url you might need to get the appropriate Image id so that that it can be processed using set_post_thumbnail
Assuming the custom post type as JOB and the image field as representation_image
add_action( 'save_post', 'set_cpt_featured_image_save_job', 100,3 );
function set_cpt_featured_image_save_job( $post_id, $post, $update ) {
// Replace with your CPT name so that it runs only on specific post type
if ( 'job' !== $post->post_type ) {
return;
}
// get the image ID from the post custom field , $_POST['wpcf-representation_image'] Gives the image url,
// see <em><u>hidden link</u></em>
// set the cpt post feature image using set_post_thumbnail
// see https://developer.wordpress.org/reference/functions/set_post_thumbnail/
}