Problem: I have a CRED form that creates child posts. I would like to have the parent post be automatically assigned as the current post where the CRED form is displayed. I would also like a custom field value to be automatically the current User's name.
Solution:
There are two ways you can predefine a CRED form field value. You can use the "value" attribute, or you can use the "urlparam" attribute. The value attribute allows you to pass a value in using another shortcode, and the urlparam attribute allows you to capture a URL parameter variable and use that as the value.
You can use the wpv-user shortcode and the value attribute to predefine the user's name:
[cred_field field="your-field-slug" post="your-post-type-slug" value="[wpv-user field='user_firstname'] [wpv-user field='user_lastname']"]
The urlparam value will pass in a URL parameter value to any field:
[cred_field field='_wpcf_belongs_parentslug_id' urlparam='wpvpostparent' select_text='--- not set ---' class='form-control' output='bootstrap']
Then you can link to your CRED form page using the wpvpostparent URL parameter to specify a parent post ID:
http://yoursite.com/cred-form-page?wpvpostparent=12345
If you want to use the current post ID as the value of the parent field, you can use the wpv-post-id shortcode and the $current_page operator:
[cred_field field='_wpcf_belongs_parentslug_id' value='[wpv-post-id id='$current_page']' select_text='--- not set ---' class='form-control' output='bootstrap']
Pro tip: if you want to hide the predefined parent select field you can wrap it in a hidden div:
<div style="display:none;"> [cred_field field='_wpcf_belongs_parentslug_id' value='[wpv-post-id id='$current_page']' select_text='--- not set ---' class='form-control' output='bootstrap'] </div>
Relevant Documentation:
https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_field
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-id
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-user
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 |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 2 replies, has 2 voices.
Last updated by 7 years, 1 month ago.
Assisted by: Christian Cox.