Support

Account

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

  • Just after the post is saved

    
    function add_image_to_acf_field($post_id) {
      if (has_post_thumbnail($post_id)) {
        $post_thumbnail_id = get_post_thumbnail_id($post_id);
        // notice that I'm using the field key here
        update_field('field_4fc5ab37e1819lol', $post_thumbnail_id, $post_id');
      }
    }
    add_action('save_post', 'add_image_to_acf_field');