Home › Forums › Backend Issues (wp-admin) › Set image as featured image › Reply To: Set image as featured image
Hi Jonathan,
We are going to use ACF to create a new featured image to replace the existing core featured image in posts. We have an existing multisite with Polylang. The code is working great on our development site. It replaces, updates, removes, etc etc .. works great.
But.. it doesn’t show the current selected core featured image when you edit the post the first time. When you click edit on a post it doesn’t show a featured image for the new ACF featured image even though the post has one attached to it.
How can we put the existing core image into the ACF image when you click edit the first time?
// REPLACE FEATURED IMAGE WITH ACF
function acf_set_featured_image( $value, $post_id, $field ){
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=pfimage’, ‘acf_set_featured_image’, 10, 3);
// hide existing featured image
add_action(‘admin_head’, ‘my_admincss’);
function my_admincss() {
echo ‘<style>
#postimagediv.postbox {
display: none !important;
}
</style>’;
}
// END REPLACE FEATURED IMAGE WITH ACF
Thanks,
David
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!
ACF wouldn’t be so widely used in WordPress if it didn’t have some pretty amazing capabilities. In this article, we look at a few of the features we’ll discuss during “7 things you didn’t know you could do with ACF” at #WPEDecode later this month. https://t.co/5lnsTxp81j pic.twitter.com/Yf0ThPG1QG
— Advanced Custom Fields (@wp_acf) March 16, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.