• I have a Guttenberg block that takes an image (much like the image block). When it is updated or added I am trying to change the featured image to that. Unrelated, but note that I am using ACF plugin for this.

    I am using update_post_meta($post_id, '_thumbnail_id', $value) when the state of that ACF image block is updated. I think it is working as intended and updating the featured image field properly. But the issue is that the thumbnail isn’t refreshing until it is saved or posted or updated. While it is good enough for the most part. Is there a function to refresh the featured image section in post edit mode? Or is there a better way to change the featured image from an editor? set_post_thumbnail doesn’t seem a good idea here.

    • This topic was modified 3 years, 1 month ago by fusan.
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    set_post_thumbnail($post_id, $value) is essentially just a wrapper for update_post_meta($post_id, '_thumbnail_id', $value). You could use it, but it wouldn’t help the current UI image. You need some sort of JavaScript to update the current UI image whenever the field is changed. Add an onchange event listener to the field element. It then updates the related img element’s src attribute.

Viewing 1 replies (of 1 total)
  • The topic ‘How to refresh thumbnail for featured post after using update_post_meta()’ is closed to new replies.