• Hello,
    I want to replace the featured images with the image created with your plugin,
    can anyone suggest a filter or action to add to function.php to do this?
    Thank you

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author joppuyo

    (@joppuyo)

    Hey, here’s the code I’ve been using on my own projects.

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

    Just change the field name to the one you are using on your site. Keep in mind that this only works if the return type is set to array or id.

    If you set the field name to _thumbnail_id, it will replace the featured image. No additional code needed, you just might want to set the featured image to hide on screen.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Set as featured image’ is closed to new replies.