Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 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

1 Answer 1

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) – dalbaeb Apr 29 at 18:33
Thanks for pointing that out @dalbaeb! – fischi Apr 29 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! – dalbaeb Apr 29 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.