Problem: I would like to access the name of the page where my CRED form is included, in the post created by the CRED form. The page where the form is shown has no parent/child relationship to the post created by CRED.
Solution: Use a generic field in your CRED form to capture the current page ID. Use the page ID to get the page title, then update your post's meta information to include the page title.
[cred_generic_field field='currentpageid' type='textfield' class='' urlparam=''] { "required":0, "validate_format":0, "default":"[wpv-post-id]" } [/cred_generic_field]
add_action('cred_save_data', 'save_parent_title',10,2); function save_parent_title($post_id, $form_data) { // if a specific form if ($form_data['id']==550) { if (isset($_POST['currentpageid'])) { $parent_title = get_the_title($_POST['currentpageid']); update_post_meta($post_id, 'wpcf-field-name', $parent_title, true); } } }
Relevant Documentation: https://toolset.com/documentation/user-guides/cred-api/#csd
https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_generic_field
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.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
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 23 replies, has 3 voices.
Last updated by oriolc 7 years, 2 months ago.
Assisted by: Christian Cox.