-
-
Save apsolut/6903394879cea852c2bf086016907ce7 to your computer and use it in GitHub Desktop.
WordPress | Set ACF image to be the WP feature image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Because WP does not allow us to set minimum image dimensions on upload we often | |
* use an ACF image. However this means within the dashboard we lack a thumbnail | |
* Here we set the ACF image to be the WP thumbnail. | |
*/ | |
function image_to_thumbnail( $post_id ) { | |
if( get_post_type($post_id) != 'talent' ) { | |
return; // Stop if post-type is not talent | |
} | |
$featured_image = get_field('featured_image', $post_id); | |
if( $featured_image ) { | |
$attachment_id = $featured_image['ID']; | |
set_post_thumbnail( $post_id, $attachment_id ); | |
} | |
} | |
add_action( 'save_post', 'image_to_thumbnail' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment