Currently I use types_get_fields() to retrieve a list of custom post fields from Toolset. However, the list only contains those fields added by Toolset. When creating a View, Toolset is also able to show other fields like post id/slug/title but also fields added by third party themes and plugins.
If I use an event calendar plugin for example and on one of the post types added by the event calendar has some custom fields, in a View, Toolset allows me to use these fields. I now want to extend my Toolset for Divi plugin so it supports those fields as well.
How can I ask Toolset for a list of all possible fields and how can I then render those fields on the frontend?
Please find attached an image of the post type with the custom fields, added by the event calendar plugin, my Divi plugin showing the list of text fields retrieved by types_get_fields() and the Toolset View where the fields are available.
For non-Types fields you can just use the standard WordPress function get_post_meta.
You pass a post ID as the first argument.
If you don't pass any more arguments it will retrieve *all* the post meta as an array. The values will be the raw values as stored in the database, and you may want to format them differently before outputting them, but that will depend entirely on the custom fields.
(Types custom fields are also standard post meta, saved with a wpcf- prefix, so a Types field of 'priority' would be saved with a key of 'wpcf-priority'.)
Note that post meta keys that begin with an underscore (e.g. "_VenueAddress") are 'hidden' fields, they would not normally show on post edit screens when you choose to display custom fields.
Ah so when I click the button on the view to load non toolset post fields, toolset under the hood also only calls get_post_meta, right?
That would explain a lot. And thanks for the hint with the underscore. I was wondering why the fields didn't show in the list but the plugin adds a custom meta box in which it shows those fields. So thats the reason.
I haven't dug into the Views code to know what actually happens when you click the load non-Toolset post fields button does, but it surely must use get_post_meta.
Types fields are just WordPress post meta at the end of the day, but Types has special handling to know that a Select field—although stored just as a string of the selected option—has options available and should be rendered as a select field in the back end and in Toolset Forms.