I am trying to: allow users who use a CRED post form to choose a featured image from one which exists in the media library
Without this, I can see the media library getting pretty big and potentially containing lots of duplicate images as each post will contain a "new" image from an outside source
Hi Nick,
I can see how selecting an image instead of uploading one would save server space. There is not currently a good way for CRED to access your Media Library directly, and this idea has been sent along to our developers on several occasions as a feature request. Unfortunately I do not have a timeline for when it may be implemented.
It is possible to use a WYSIWYG editor in your CRED form, which would include a button to open the Media Library and allow someone to pick an existing image. This approach isn't ideal because there is no guarantee your user will do what you want them to do. They may put text in instead of an image, so validation here isn't very effective.
It is also possible to upload your own images to the library and build your own form input that allows users to select one. Then you could store a reference to that image in your custom post type as a custom field. That would require a bit of custom code in your CRED template, and possibly some understanding of the CRED API.
You may be interested to read this forum post:
https://toolset.com/forums/topic/add-media-button-instead-of-choose-file-button-in-cred-forms/
Some other users have discussed their approaches to this same issue. Hopefully you can tweak one of these options to meet your needs. Please let me know if I can be of further assistance with this.
Thanks. Maybe you can add my "vote" for this to be moved up the development priority list?!
When you say I can include a WYSIWYG editor and "hope" people choose an image, I'm not sure how to do this and ensure that the image becomes the featured image.
Thanks
It would require custom PHP code that hooks into the save_post action. You would need to access the post's attachments and use the set_post_thumbnail function to set the post's featured image. Something similar is done in this other post, but they use an image upload field instead of an existing Media Library item:
https://toolset.com/forums/topic/featured-image-from-image-field/