Extract image from content and set it as the featured image

Why not utilize two hooks, one before post saved and one after post saved?

content_save_pre : Function attached with this hook will remove image from content and store it in session/transient.

save_post : With this hook you will have id of post. Function attached with this hook will set featured image for the post with that id and delete session/transient data.

Alternatively, If you want to go with your approach, I think you should use post_name, instead of guid, to retrieve post id from database.

Leave a Comment