Support

Account

Home Forums General Issues Automatically fill image field with post_thumbnail Reply To: Automatically fill image field with post_thumbnail

  • I just tested it out and it worked for me. The key of the field you should be able to see when editing the field group.

    Check Screen Options -> Show Field Keys

    The only thing I can think of is that the field key is wrong…

    Or that update field is not working because it’s on the front end.

    Is this image field part of something more complex, like a repeater or flexible content? If not you could try the following:

      function add_image_to_acf_field($post_id) {
        if (has_post_thumbnail($post_id)) {
          $post_thumbnail_id = get_post_thumbnail_id($post_id);
          $image_field_name = 'image_field';
          $image_field_key = 'field_54ea66db22c08';
          update_post_meta($post_id, $image_field_name, $post_thumbnail_id);
          update_post_meta($post_id, '_'.$image_field_name, $image_field_key);
        }
      }
      add_action('save_post', 'add_image_to_acf_field');