Home › Forums › ACF PRO › Connect ACF to Featured Image. › Reply To: Connect ACF to Featured Image.
If an ACF field can be used to set a featured image, can’t you simply use the same field names.
So if someone adds to the featured image, does it not add to the ACF field? Not tried it but in theory, should be the same function.
I believe you need the field as an image with the label of post_image.
Possibly more to it, I don’t know.
You may need to reverse the following code:
add_action('acf/save_post', function ($post_id) {
$value = get_field('post_image', $post_id);
if ($value) {
if (!is_numeric($value)) {
$value = $value['ID'];
}
update_post_meta($post_id, '_thumbnail_id', $value);
} else {
delete_post_meta($post_id, '_thumbnail_id');
}
}, 11);
But get the featured post ID using get_post_thumbnail_id then pass the value/details back to your 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.