Skip Navigation

[Resolved] select type field

This support ticket is created 5 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.

This topic contains 1 reply, has 2 voices.

Last updated by Beda 5 years, 1 month ago.

Author
Posts
#1204737

Tell us what you are trying to do?
I am wondering if it is possible to create a new post type where a front end user can choose a value from a "select" field that is dynamic (i.e. pulling data from a query specifically from another post type).

Is there any documentation that you are following?
I looked at the adding custom fields documentation but they are basic. I think what I am trying to do is more advaned

Is there a similar example that we can see?
No that I am aware of.

What is the link to your site?
hidden link

#1204956

A front end user, this would mean, thru a Toolset Form.

In Toolset Forms, you can add generic fields that are populated by a ShortCode.
So yes, you can create a ShortCode, which pulls the data from another Post Type or Post and then displays those values in the Generic Select Field of the Form.
The user can choose it, and with some Custom Code applied on cred_save_data() hook you can then persist that value to the database.

Note, that to have this working, you need to use Toolset Forms' Expert Edit Mode, because of this BUG:
https://toolset.com/errata/generic-fields-in-new-drag-and-drop-editor-will-not-persist-the-shortcode-passed-as-source/

How to create such a ShortCode is not subject of Support, however, it needs to match an exact syntax which is a JSON valid format, as explained in the Generic Fields GUI of Toolset forms (choose either Select, Checkboxes or Radio Generic Fields)

To persist the field in the database you can either add persist:1 to the Generic Field (but that is deprecated) or, use a cred_save_data() action to get the chosen Fields Values from the $_POST global and update some field in the Database with it.
cred_save_data() is explained here, and you can then use upate_post_meta() for example to persist the field:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://codex.wordpress.org/Function_Reference/update_post_meta

What you can also do, is generate the ShortCode with a View, this means, you create a View and in its loop, you generate the JSON valid output, then, you select to no wrap the View in any DIV, and use that View as ShortCode to populate the Generic Form Field.
Since Views is a pretty dynamic content render and query tool, you can basically output anything you want in its loop.

You will face 3 main challenges here:
- create the view or shortcode that produces valid JSON
- persist the field in the database
- work in Forms "Expert Mode" which allows no drag and drop

Please let me know if you need further help with this, I can assist such process and review custom code, but not craft it to 100% for you.
However our forum presents a large number of tickets where this topic was already elaborated as well, hence, these might be of great help to start:
hidden link..69i57j69i58.9725j0j4&sourceid=chrome&ie=UTF-8
- https://toolset.com/forums/topic/cred-generic-field-with-view-shortcode/
- https://toolset.com/forums/topic/populate-select-cred-generic-field-with-a-view/
- https://toolset.com/forums/topic/how-to-display-multiselect-generic-field-in-views/

Please ignore all the mentions of "views cannot produce a raw loop".
That is past, nowadays you can do this by simply checking the box to not wrap the view in any HTML, just below the View's Loop Editor.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.