carbon-fields icon indicating copy to clipboard operation
carbon-fields copied to clipboard

How to add custom fields to attachments?

Open lautiamkok opened this issue 3 years ago • 2 comments

Just a question:

How do we add custom fields to attachments with Carbon Fields?

lautiamkok avatar Aug 23 '22 12:08 lautiamkok

Been wondering the same question

jorgedodoplugin avatar Aug 26 '22 03:08 jorgedodoplugin

https://docs.carbonfields.net/learn/fields/file.html#config-methods

Is this document helpful?

arafatjamil01 avatar Aug 26 '22 10:08 arafatjamil01

Hi @lautiamkok ,

In order to create custom fields for the attachment post type you only have to specify the "post_type" where clause in the post_meta container.

Here is an example of usage:

Container::make( 'post_meta', __( 'Attachment Settings', 'crb' ) )
  ->where( 'post_type', '=', 'attachment' )
  ->add_fields( array(
    Field::make( 'text', 'crb_attachment_content', __( 'Additional Content', 'crb' ) )
  ) );

Then you could enter the "Edit Post" page of every attachment and use the fields. When you open an attachment popup click on the "Edit more details" link to get to the "Edit Post" page. Here is an example image: https://i.imgur.com/QEHimUD.png

HTMLBurger-NG avatar Feb 17 '23 09:02 HTMLBurger-NG