0

I am looking for an option where a custom meta value will be saved when user uploads an attachment.

Lets say I need a meta key _example_meta_key and want to save meta value of this as ex087659bh (It will be a randomly generated number, I can take care of this.)

However, The problem is, I can't seem to find any filters to add custom meta value on upload. There are some tutorials which shows the way to add fields in media edit form but I need this to be executed at the time of file upload.

Any help would be much appreciated.

Thanks

  • Are you referring to admin area uploading or do you have custom frontend uploading via media_handle_upload()? – N00b Dec 18 '15 at 22:35
  • Core admin pages. I am just trying to alter the media upload process, so it saves an additional post meta when it processes the upload. – Abdul Awal Dec 19 '15 at 1:19
0

If you are uploading via Core admin pages, WordPress will most likely upload the file, and then create an attachment post-- that is, a post with the attachment post type. So the save_post_attachment hook might do it for you.

3362            /**
3363             * Fires once a post has been saved.
3364             *
3365             * The dynamic portion of the hook name, `$post->post_type`, refers to
3366             * the post type slug.
3367             *
3368             * @since 3.7.0
3369             *
3370             * @param int     $post_ID Post ID.
3371             * @param WP_Post $post    Post object.
3372             * @param bool    $update  Whether this is an existing post being updated or not.
3373             */
3374            do_action( "save_post_{$post->post_type}", $post_ID, $post, $update );

It is hard to be very specific given how general the question is.

  • Thanks for the answer, I'll give it a try and let you know. – Abdul Awal Dec 19 '15 at 1:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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