Home › Forums › General Issues › Automatically fill image field with post_thumbnail › Reply To: Automatically fill image field with post_thumbnail
Just after the post is saved
function add_image_to_acf_field($post_id) {
if (has_post_thumbnail($post_id)) {
$post_thumbnail_id = get_post_thumbnail_id($post_id);
// notice that I'm using the field key here
update_field('field_4fc5ab37e1819lol', $post_thumbnail_id, $post_id');
}
}
add_action('save_post', 'add_image_to_acf_field');
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.