With the classic “Posts” post type, the featured image is saved, but not with custom post types.
Interestingly, when I pass show_in_rest
to false
(thus deactivating Gutenberg editor and switching to the classic editor), the featured image is saved when I publish.
Desperate, I tried to add update_post_meta($post->ID, '_thumbnail_id', filter_input(INPUT_POST, '_thumbnail_id'));
to the save_post
hook but it didn’t solved the problem, for the simple reason that _thumbnail_id
is empty in the global $_POST
variable (I assume this because I checked the wp_postmeta
table and found that the meta_key _thumbnail_id
of that post is set to NULL).
So either Gutenberg fails to attach the image selected to the _thumbnail_id
input, or something wrong happen during the saving process — unfortunately I don’t know how to debug that process, or even at least get the content of the global $_POST
as its done via ajax.
Any help is welcome!
WordPress 6.5