Problem:
I want to add data to the title of the currently submitted post with Toolset Forms, the data should come from the parent (related) post of the currently submitted post.
How can I do that?
Solution:
There are 2 options, both need be hooked to a Forms API hook.
You can listen to the Form's inputs in $_POST and get the value from the select2 Field where you use to select the related post in Toolset Forms (if you have this field present).
Then, you can update the Post you are editing with that of that post by simply using the value returned by the $_POST of the Select2 Parent field, which is the ID of the parent post.
With that ID you can get any information about this post using the WordPress API and populate your post as well using the WordPress API.
The select2 for parent selectors in the $_POST will be available with something link `$_POST['@post-type_right-post-type_parent'];`
You can get it's precise value by dumping the $_POST in the Form, to use the precise slug of your relationship selector.
All these actions need to be hooked to cred_save_data(), to fire at the right moment when the Form saves it's data to the database.
The other approach is using the Toolset Relationships API hook toolset_get_related_post() to get the (one) related post to the currently edited one.
This should be done on a cred_submit_complete() Toolset Forms hook to ensure all data, inclusive relationships, are stored in the database already.
Then we can get the related Post ID, and again with that ID, we can get the post data using WordPress API.
From here on the process is the same as with the first approach.
There is a good example here using Toolset Relationships API:
https://toolset.com/forums/topic/get-parent-id-on-new-cred-form-submission/#post-1271597
An example using the $_POST would be the same as above just you have the ID from `$_POST['@post-type_right-post-type_parent'];`. You don't need the Relationships API in this case.
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 |
---|---|---|---|---|---|---|
- | - | 14:00 – 20:00 | 14:00 – 20:00 | 14:00 – 20:00 | 14:00 – 20:00 | 14:00 – 20:00 |
- | - | - | - | - | - | - |
Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)
This topic contains 4 replies, has 2 voices.
Last updated by 5 years, 7 months ago.
Assisted by: Beda.