1

I know this has been asked before but I'm having trouble with it and this seems poorly documented.

My goal:

Create a function that adds multiple custom fields into each item in the media gallery. What I ideally want is that:

  • these would only show on audio media items
  • these fields would be things like "lyrics", "cover artist", "original artist" so would be ideal if these can appear under the built in Metadata tab on the audio [Fig 1]
  • they would also appear in the quick view along with the other metadata. [Fig 2] The code that works already does this but I want to retain this function.

Website details

My website is a wordpress v5.6.2 website with a handful of fairly popular plugins: Content Control by Code Atlantic, Filebird by Ninja Team, Ultimate Member by Ultimate Member, UpdraftPlus backup/restore by Updraftplus.

 

What I've tried

I've tried a few things, these don't work for me:

Not tried:

I've found these but after all the failed attempts above I'm not sure these are going to be any better! but for reference:

 

What does work:

  • How to add a custom field to the media screen (image/gallery)? - the top voted answer on this question is the only example I've got to work so far. It adds a field into every single media gallery item, and I could add some more fields and use it if all else fails but I'd like to get a cleaner solution for this incorporating all 3 points above. This can be seen on Fig 1 and Fig 2 - the new field called "Style"

Can anyone help me make a function that adds fields in as per my 3x points above? I'd appreciate an answer even if it only answers 1 or 2 of the points though, I've put them in order of what's most important.

Screenshots

Fig 1:

enter image description here

Fig 2:

enter image description here

3
  • You can use wp_get_attachment_id3_keys to add custom fields into the Metadata metabox, however, you'll be limited to single-line text fields only (i.e. the <input> tag). So you should probably just use the attachment_fields_to_edit hook, if you want to be able to have other field types like textarea.
    – Sally CJ
    Commented Feb 25, 2021 at 14:36
  • @SallyCJ thanks - as you say I do want textarea at least for lyrics. I will have a look though, it might be worth using this for the other fields.
    – AutoBaker
    Commented Feb 25, 2021 at 18:56
  • The other possible option if you want textarea and other field types, is by removing the default metabox and create your own based on the original source. But I didn't mention that before because you'd still need to use the attachment_fields_to_edit hook to add your fields to the "Attachment details" popup in Fig 2, so I thought, "why bother with the metabox"?
    – Sally CJ
    Commented Feb 25, 2021 at 22:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.