Support

Account

Home Forums Front-end Issues Set image as featured image – ACF Image Crop Add-on Reply To: Set image as featured image – ACF Image Crop Add-on

  • Author plugin answered in this topic.

    This code works.

    function acf_set_featured_image( $value, $post_id, $field  ){
      $id = $value;
      if( ! is_numeric( $id ) ){
        $data = json_decode( stripcslashes($id), true );
        $id = $data['cropped_image'];
      }
      update_post_meta( $post_id, '_thumbnail_id', $id );
      return $value;
    }
    
    // acf/update_value/name={$field_name} - filter for a specific field based on it's name
    add_filter( 'acf/update_value/name=fieldname', 'acf_set_featured_image', 10, 3 );