WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have made a plugin for wordpress which copies the image to another directory when a post has been edit. But if you only upload another featured image and don't save the post. The image has been attached to the post, but the post has not been updated. Which does not trigger my plugin function. Show which trigger (action hook) can I use to also copie the featured image?

The action which I now use for the post edit is wp_insert_post().

I forgot the reason why I use wp_insert_post(), but maybe that's why it fails ;)

share|improve this question

migrated from stackoverflow.com Dec 20 '12 at 4:44

This question came from our site for professional and enthusiast programmers.

Please show your actual code. – kaiser Dec 20 '12 at 8:04
up vote 3 down vote accepted

The set_post_thumbnail function uses the metadata functions to set the featured image.

You have two actions to hook into that process:

EDIT: The action hooks are now defined different

Thanks @dalbaeb!

  • update_postmeta, before the data is written into the database. Previously update_post_meta
  • updated_postmeta, after the data is written into the database. Previously updated_post_meta

SECOND EDIT: No need to panic

updated_{$meta_type}_meta and update_{$meta_type}_meta still work.

You will have to make a conditional, and be good to go:

if ( $metakey == '_thumbnail_id' ) { /*blabla*/ }
share|improve this answer
I believe now it is updated_postmeta (link) and update_postmeta (link) – montrealist Apr 29 '15 at 18:33
Thanks for pointing that out @dalbaeb! – fischi Apr 29 '15 at 19:00
Actually upon further inspection there's also updated_{$meta_type}_meta (link) and update_{$meta_type}_meta (link) actions, so technically all four will work. Sorry about that! – montrealist Apr 29 '15 at 20:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.