Created
November 2, 2016 18:24
-
-
Save ben-heath/f070c4cb576531bb3ae102a5b7c4b4ba to your computer and use it in GitHub Desktop.
Save value of ACF form field to the featured image of the post.
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 | |
function acf_set_featured_image( $value, $post_id, $field ){ | |
if($value != '' && 'location' == get_post_type()){ | |
//Add the value which is the image ID to the _thumbnail_id meta data for the current post | |
update_post_meta($post_id, '_thumbnail_id', $value); | |
} | |
return $value; | |
} | |
// acf/update_value/name={$field_name} - filter for a specific field based on it's name | |
add_filter('acf/update_value/name=location_featured_image', 'acf_set_featured_image', 1, 3); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment