Support

Account

Home Forums Backend Issues (wp-admin) Set image as featured image Reply To: Set image as featured image

  • Well if $value is the entire repeater you could do something like this:

    
    // Set the first sock image uploaded as the featured image
    function acf_set_featured_image( $value, $post_id, $field  ){
        
        if(isset($value) && is_array($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[0][sock_image]);
        }
     
        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);
    

    That is if you’ve set the return value of the image field to URL. Otherwise you’ll have to do a bit more with it..

    But really you should activate wp_debug and do an error_log($value); inside the function to find out what value is first.