Support

Account

Home Forums General Issues Add Image Size to another ACF Field Reply To: Add Image Size to another ACF Field

  • Hi @neodjandre

    You should be able to do it by using the acf/save_post hook like this:

    function my_acf_save_post( $post_id ) {
        
        // get image id
        $image_id = get_field('fl_image', $post_id, false);
        
        // set the thumbnail field key
        $thumbnail_field_key = 'field_1234567890abc';
        
        // set the value of the thumbnail field
        update_field($thumbnail_field_key, $image_id, $post_id);
        
    }
    
    // run after ACF saves the $_POST['acf'] data
    add_action('acf/save_post', 'my_acf_save_post', 20);

    Where field_1234567890abc is the field key you want to update. After that, you can get the value like this:

    $thumb_image = get_field(thumbnail_id);
    $thumb_url = $thumb_image['sizes']['thumbnail'];

    If you are using a URL custom field to store the URL, you should be able to do it like this:

    function my_acf_save_post( $post_id ) {
        
        // get image id
        $image = get_field('fl_image', $post_id);
        
        // set the thumbnail URL field key
        $thumbnail_url_field_key = 'field_1234567890abc';
        
        // set the value of the thumbnail URL field
        update_field($thumbnail_url_field_key, $image['sizes']['thumbnail'], $post_id);
        
    }
    
    // run after ACF saves the $_POST['acf'] data
    add_action('acf/save_post', 'my_acf_save_post', 20);

    Then you can get the URL like this:

    $thumb_image = get_field(thumbnail_id);

    I hope this helps 🙂