Home › Forums › Backend Issues (wp-admin) › Set image as featured image › Reply To: Set image as featured image
Hi,
Thank you for the detailed feed. I have been struggling to get this working on my site for the past hour.
I am trying to set the first image in a repeater row as the featured image for each existing and new post.
The repeater is called sock_image and the image field is called sock_images. Any clue on what I am doing wrong? This is what I put in my functions file:
// Set the first sock image uploaded as the featured image
function acf_set_featured_image( $value, $post_id, $field ){
if($value != ''){
delete_post_thumbnail( $post_id);
//Add the value which is the image ID to the _thumbnail_id meta data for the current post
add_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=sock_images', 'acf_set_featured_image', 10, 3);
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.