Skip Navigation

[Resolved] How to display media custom fields in single page

This support ticket is created 6 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 3 replies, has 2 voices.

Last updated by Waqar 6 years, 1 month ago.

Assisted by: Waqar.

Author
Posts
#1137541

Hi,

I've added custom fields to the media post type, but I'm having a couple of issues.

1) Is there a way of getting these fields to display when using 'add media' in the post editor?

2) I don't know how to get the field data to display on the front-end. I have a custom single template, and I'd like to get the field data to display underneath each image on the single post page.

#1138073

Hi Andrew,

Thank you for contacting us and I'll be happy to assist.

1) Is there a way of getting these fields to display when using 'add media' in the post editor?

- To show custom fields data on the "Add Media" screen, you can use "attachment_fields_to_edit" filter, as shown in this example:
https://wordpress.stackexchange.com/a/307585

2) I don't know how to get the field data to display on the front-end. I have a custom single template, and I'd like to get the field data to display underneath each image on the single post page.

- You can get and show the custom fields data for the media post type (same as with other post types), using "Types Fields API".

We have detailed reference, along with examples at:
https://toolset.com/documentation/customizing-sites-using-php/functions/

I hope this helps and let me know if you need any further assistance.

regards,
Waqar

#1141239

Hi Waqar,

Thanks for getting back to me.

On the second point, I understand how to display the field data for specific items, but I'm not clear how to display it for media items that have been added via the WordPress content editor. For example, I have added a custom text field for 'attribution' that I would like to display under every image that's added via the editor. Can you tell me how to do that?

Many thanks.

#1142216

Hi Andrew,

Thanks for writing back and for sharing further details.

I'm afraid, this will require a custom function that filters the content added in the post body, possibly attached to "the_content" filter:
https://codex.wordpress.org/Plugin_API/Filter_Reference/the_content

Since this question is related to WordPress' default functionality and not specifically Toolset plugins, I'll recommend posting this to WordPress development forums, for the most accurate and efficient suggestions/workarounds.

https://wordpress.org/support/
https://wordpress.stackexchange.com/

regards,
Waqar