Support

Account

Home Forums ACF PRO Connect ACF to Featured Image.

Solving

Connect ACF to Featured Image.

  • I know there is a way to upload an image to an ACF field and then have it become teh featured image, but is there any way to connect the featured image to an ACF field? I am making a Digital Asset management system. Whenever a photo is uploaded to WP, I have a way to automatically create a new post and then make the image a featured image. I then have the Media Library Assistant pull ACF fields from the image. But I need to get the featured image to be an ACF image field to show up on the post. Any ideas are appreciated.

  • If an ACF field can be used to set a featured image, can’t you simply use the same field names.

    So if someone adds to the featured image, does it not add to the ACF field? Not tried it but in theory, should be the same function.

    I believe you need the field as an image with the label of post_image.

    Possibly more to it, I don’t know.

    You may need to reverse the following code:

    add_action('acf/save_post', function ($post_id) {
        $value = get_field('post_image', $post_id);
        if ($value) {
            if (!is_numeric($value)) {
                $value = $value['ID'];
            }
            update_post_meta($post_id, '_thumbnail_id', $value);
        } else {
            delete_post_meta($post_id, '_thumbnail_id');
        }
    }, 11);

    But get the featured post ID using get_post_thumbnail_id then pass the value/details back to your ACF field

  • What I do is that I create an image field. I use “Featured Image” as the field label and “_thumbnail_id” as the field name. Then in the settings for the field group I hide the WP featured image box. When adding an image this way it automatically becomes the featured image without any coding. You can either get the image using ACF functions or the WP functions that deal with the featured image.

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

You must be logged in to reply to this topic.