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);