Last active
January 23, 2018 12:51
-
-
Save mattradford/5d097d41e326ffeeee33 to your computer and use it in GitHub Desktop.
Set post thumbnail from gallery. Saves a performance hit.
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
function set_featured_image_from_gallery() { | |
$has_thumbnail = get_the_post_thumbnail($post->ID); | |
if ( !$has_thumbnail ) { | |
$images = get_field('gallery', false, false); | |
$image_id = $images[0]; | |
if ( $image_id ) { | |
set_post_thumbnail( $post->ID, $image_id ); | |
} | |
} | |
} | |
add_action( 'save_post', 'set_featured_image_from_gallery' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment