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.
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
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.
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