Home Forums General Issues Set featured image from ACF image field


Set featured image from ACF image field

  • I am looking for a way to automatically set the featured image of a post or custom post type, to the image uploaded on a custom image field.

    any ideas?


  • This is covered pretty well here let me know if you have any questions.

  • yes the code is – works with custom post types too:

    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=cursusfoto', 'acf_set_featured_image', 10, 3);
  • I know this is an old topic, but after doing this for some time I’ve just recently realized that using a filter isn’t needed. All you really need to do is create an image field with the field name of “_thumbnail_id”, and ACF will just update the featured image for you. There’s no error checking, but simply making your image field required deals what that problem.

    Just thought I add this for anyone that finds this topic.

    • Vasili

    • May 4, 2017 at 8:31 pm


    John Huebner,

    Just found this topic, thank you for writing this!

  • The more I use ACF, the more I like (and understand) it but now I’ve got a small problem.
    I need to copy the image-url from the options page to the featured image of a new post. The image is already uploaded. My code is not functioning… Can you give me a hint?

    PS: field_5dc3135e281b9 is the fieldkey and _thumbnail_id is the fieldname of the option field with the image.

    function acf_set_featured_image( $value, $post_id, $field ){
    $value = get_field(‘_thumbnail_id’, ‘options’); // get image from optionspage
    add_post_meta(‘$post_id’, ‘_thumbnail_id’, $value);
    return $value;
    add_filter(‘acf/update_value/key=field_5dc3135e281b9’, ‘acf_set_featured_image’, 10, 3);

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.