Newbie_prog
Newbie_prog

Reputation: 23

How to display Featured Image in post type of ACF FORM as Image field

Here's my code at functions.php and still can't set as featured image in the post type of the blog.

 add_action('acf/save_post', 'acf_set_featured_image');

function acf_set_featured_image($post_id){
    $value = get_field('daily_selfie', $post_id);

    if($value != ''){
        add_post_meta($post_id, '_thumbnail_id', $value);
    }

    return $value;
}

Upvotes: 0

Views: 3427

Answers (1)

Greg
Greg

Reputation: 473

Try this

function acf_set_featured_image( $value, $post_id, $field  ){

    if($value != ''){
        //Add the value which is the image ID to the _thumbnail_id meta data for the current post
        add_post_meta($post_id, '_thumbnail_id', $value);
    }
    return $value;
}

// acf/update_value/name={$field_name} - filter for a specific field based on it's name
add_filter('acf/update_value/name=foo', 'acf_set_featured_image', 10, 3);

Upvotes: 1

Related Questions