Is it possible to add a custom meta box for the images of the media library?How I achieve this using add_post_meta() function?


Sure! Just follow this guide and make these changes:

And of course, make sure to customize the example code to your specific needs.

| improve this answer | |
  • I will read your suggested links and try to apply the concept. After the implementation, how I will obtain the associated custom data of a metabox of an attachment? – sialfa Nov 4 '19 at 14:31
  • You can get it using the get_post_meta() function. It's used in the guide, under the Getting values section. – Cas Dekkers Nov 4 '19 at 14:46
  • I've read the Getting value section, I need to pass the post id to the function, will the post id work instead of the attachement id that is related to the images? – sialfa Nov 4 '19 at 17:50
  • Attachments are stored in the same database table, wp_posts by default, so you can use the ID of the attachment as the $post_id parameter. – Cas Dekkers Nov 5 '19 at 13:17

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.