Q:

Set Wordpress excerpt and post thumbnail based on custom field

As stated in the title, I would like to automatically save/update the value of post_excerpt and post_thumbnail based on an ACF custom field (mostly for compatibily reasons with other plugins). Now, while tring to accomplish this I encountered 2 issues, first being with the following function: 
function test_FeaturedImageSetByACF() {

    $current_screen         = get_current_screen(); // Current admin screen needed to identify the current cpt
    $current_cpt_name       = $current_screen->post_type; // Current cpt name
    $current_cpt_support    = 'thumbnail'; // We want to check if the CPT supports this feature

    $post_id                = get_the_ID(); // Current post ID
    $post_image_field       = get_field('post_head_img'); // ACF field we want to sync
    $post_image_id          = $post_image_field['id']; // ACF image filed ID
    $post_image_url         = $post_image_field['url']; // ACF image filed URL

    // If current cpt supports thumbnails/featured images

    if ( post_type_supports( $current_cpt_name, $current_cpt_support ) ) {

        if ( ( $post_image_url ) AND ( ( $post_image_url ) != ( get_the_post_thumbnail() ) ) ) {

            delete_post_thumbnail( $post_id );
            set_post_thumbnail( $post_id, $post_image_id );

        }

    }

}

add_action('save_post', 'test_FeaturedImageSetByACF', 13, 2 );
add_action('publish_post', 'test_FeaturedImageSetByACF', 10, 2 );

It does work, however sometimes it seems to update the value only the second time I save (which means I have to save twice). I understand I'm either using a wrong hook, a wrong priority or something like that, but I can't figure out which one it is. 
Second issue I have, is I would like to accomplish something similar for post excerpts. Now the functions's will look alike the previous one quite a lot, but I don't know which value to update. Can anyone point me in the right direction?
Thanks in advance

A:

Since this became more of an ACF specific question rather than a generic one, I decided to post on ACF's support forums aswell were user John Huebner pointed me in the right direction. For anyone interested, the topic can be found at https://support.advancedcustomfields.com/forums/topic/set-wordpress-excerpt-and-post-thumbnail-based-on-custom-field/ while (in the event that post may get deleted or something) this is the code I used both for the excerpt part and the custom post thumbnail/featured image: 
add_action('save_post', 'flex_CustomExcerptSetByACF', 50);
function flex_CustomExcerptSetByACF() {

    global $post;

    $post_id        = ( $post->ID ); // Current post ID
    $post_excerpt   = get_field( 'post_excerpt', $post_id ); // ACF field

    if ( ( $post_id ) AND ( $post_excerpt ) ) {

        $post_array     = array(

            'ID'            => $post_id,
            'post_excerpt'  => $post_excerpt

        );

        remove_action('save_post', 'flex_CustomExcerptSetByACF', 50); // Unhook this function so it doesn't loop infinitely

        wp_update_post( $post_array );

        add_action( 'save_post', 'flex_CustomExcerptSetByACF', 50); // Re-hook this function

    }

}

add_action('save_post', 'flex_FeaturedImageSetByACF', 50);

function flex_FeaturedImageSetByACF() {

    $current_screen         = get_current_screen(); // Current admin screen needed to identify the current cpt
    $current_cpt_name       = $current_screen->post_type; // Current cpt name
    $current_cpt_support    = 'thumbnail'; // We want to check if the CPT supports this feature

    global $post;

    $post_id                = ( $post->ID ); // Current post ID
    $post_image_field       = get_field('post_head_img', $post_id ); // ACF field

    if ( ( $post_id ) AND ( $post_image_field ) ) {

        $post_image_id          = $post_image_field['id']; // ACF image filed ID
        $post_image_url         = $post_image_field['url']; // ACF image filed URL

        // If current cpt supports thumbnails/featured images

        if ( post_type_supports( $current_cpt_name, $current_cpt_support ) ) {

            if ( ( $post_image_url ) AND ( ( $post_image_url ) != ( get_the_post_thumbnail() ) ) ) {

                update_post_meta($post_id, '_thumbnail_id', $post_image_id);

            }

        }

    }

}

